Log in

EA programming => Pips or not pips ? point or not point ?

Hi , I checked out many EAs on forex forums, I should get a collection of more than 3000. There are plenty of mis unerstanading and confusion.

Even inside the book from Andrew Young, book who is a referential for everybody

This function shown by the author, can work in major cases, and for major brokers w/ major pairs. But never for exotic pairs. This function is to figure out if the broker is 4 or 4 digits.

// Pip Point Function
double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}

OK, it works, it's looks like the DigMull from VGC

double DigMull()
{
double Result=Point;

if(Digits<4)
Result=0.01; // OK
if(Digits==4 || Digits==5)
Result=0.0001;
return(Result);
}

but not for 6 digits ,, or for exotic pairs

So, I recreate a new one (very different)

double DigMull()
{
int diff_digits = 4 - MarketInfo(symbol, MODE_DIGITS);
double Result= 1 / MathPow(10, (MarketInfo(symbol, MODE_DIGITS) + diff_digits));

return(Result);
}

May be someone could tell me what he thinks about this and provide better explanation than me here...


 

Comments

  • jaguar1637 3180 days ago

    In Phoenix ea, you find this , bcozn, they calculate in pips

    if (Digits==3 || Digits==5)
    pipMultiplier=10;
    else pipMultiplier=1;

    So, SL will become (for a OPEN_BUY)

    SL = Ask - StopLoss * Point * pipMultiplier

     I.z

    ModeStopLevel = 70  (provided by the borker in 5 digits)

    ModeStopLevel * Point = 0.07

    ModeStopLevel * DigMull = 0.7  ! bad

  • jaguar1637 3179 days ago

    So, now the system (Squeletton EA) is acting like this:

    - when break even is going to be reached, (less than 2 points), the stop loss is set at its lowest as possible

    If the trade is not closed, the squeletton EA is waiting until the current price is higher than break even + TradeStop (initial StopLoss), and automatically, the Stoploss of the order is set up to this new value

    same process for take profit, except the new take profit is set to the value of TradeProfit + TradeProfit.

    I added also a profit lock stop. - when Profit Lock STOP is going to be reached, (less than 2 points), the stop loss is set at its lowest as possible. If Profit Lock Stop is bypassed , same process occurs

     

  • jaguar1637 3179 days ago

    I found different ways of calcultating the Minimum Stop Loss

    double TMinStop( string order_symbol)
    {
       return (( MarketInfo( order_symbol, MODE_STOPLEVEL) + 1.0) * 
          MarketInfo( order_symbol, MODE_POINT));
    }
    StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.

    Other guys wrote this : 
    spread=(Ask-Bid)/Point
     TMinStop= MarketInfo(Symbol(),MODE_STOPLEVEL)+spread
    in exemple
    Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point
    ______________________________________________
    double TMinStop( string order_symbol)
    {
       return (( MarketInfo( order_symbol, MODE_STOPLEVEL) + 1.0) * 
          MarketInfo( order_symbol, MODE_POINT));
    }
    
    bool TValidMarketBuyLimit( string order_symbol, double new_price)
    {
       return ( new_price <  ( MarketInfo( order_symbol, MODE_ASK) - TMinStop( order_symbol)));
    }
    
    bool TValidMarketSellLimit( string order_symbol, double new_price)
    {
       return ( new_price >  ( MarketInfo( order_symbol, MODE_BID) + TMinStop( order_symbol)));
    }
    
    bool TValidMarketBuyStop( string order_symbol, double new_price)
    {
       return ( new_price >  ( MarketInfo( order_symbol, MODE_ASK) + TMinStop( order_symbol)));
    }
    
    bool TValidMarketSellStop( string order_symbol, double new_price)
    {
       return ( new_price <  ( MarketInfo( order_symbol, MODE_BID) - TMinStop( order_symbol)));
    }
    ___________________________________________________________________________________

     
  • jaguar1637 3179 days ago

    Take a look on MT4 limitations

    http://book.mql4.com/appendix/limits

    Requirements.

    Correct prices used when performing trade operations.

    Order Type Open Price Close Price Open Price of a Pending Order Transforming a Pending Order into aMarket Order
    Buy
    Ask
    Bid
       
    Sell
    Bid
    Ask
       
    BuyLimit
        Below the current Ask price Ask price reaches open price
    SellLimit
        Above the current Bid price Bid price reaches open price
    BuyStop
        Above the current Ask price Ask price reaches open price
    SellStop
        Below the current Bid price Bid price reaches open price

    The possibility of deleting a pending order is regulated by the FreezeLevel parameter.

     

    StopLevel Minimum Distance Limitation.

    A trade operation will not be performed if any of the following conditions is disrupted.

    Order Type Open Price StopLoss (SL) TakeProfit (TP)
    Buy
    Modification is prohibited Bid-SL ≥ StopLevel TP-Bid ≥ StopLevel
    Sell
    Modification is prohibited SL-Ask ≥ StopLevel Ask-TP ≥ StopLevel
    BuyLimit
    Ask-OpenPrice ≥ StopLevel OpenPrice-SL ≥ StopLevel TP-OpenPrice ≥ StopLevel
    SellLimit
    OpenPrice-Bid ≥ StopLevel SL-OpenPrice StopLevel OpenPrice-TP ≥ StopLevel
    BuyStop
    OpenPrice-Ask ≥ StopLevel OpenPrice-SL ≥ StopLevel TP-OpenPrice ≥ StopLevel
    SellStop
    Bid-OpenPrice ≥ StopLevel SL-OpenPrice ≥ StopLevel OpenPrice-TP ≥ StopLevel

     

    FreezeLevel Limitation (Freezing Distance).

    Market orders can not be closed if the StopLoss and TakeProfit values violate the FreezLevel parameter requirements.
    StopLoss or TakeProfit orders can not be modified if StopLoss or TakeProfit values violate the StopLevel parameter requirements.
    Pending orders can not be deleted or modified if the declared open price violates the FreezeLevel parameter requirements.

    Order Type Open Price StopLoss (SL) TakeProfit (TP)
    Buy
    Modification is prohibited Bid-SL > FreezeLevel TP-Bid > FreezeLevel
    Sell
    Modification is prohibited SL-Ask > FreezeLevel Ask-TP > FreezeLevel
    BuyLimit
    Ask-OpenPrice > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
    SellLimit
    OpenPrice-Bid > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
    BuyStop
    OpenPrice-Ask > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
    SellStop
    Bid-OpenPrice > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter