Download MetaTrader 5
To add comments, please log in or register
Write your articles using our editor. It is convenient!
krystalskull
22
krystalskull 2014.02.17 06:07 

My EA performs as it should during Strategy tester (in visual mode), but when used on a demo chart it places martingale trade too early.

Strategy: Sell order is placed when conditions are met, then when price goes higher (and trade is negative) the EA is meant to place a martingale trade at the specified amount of pips

above the original sell order open price.

However, when used on a demo account (Alpari) as soon as the first sell order is placed the martingale is placed also at the same time.

It is also doing the same for the second martingale.

Has anyone seen this issue before?

I'm using Build 600.

/+------------------------------------------------------------------+
//| First Sell Order                                                 |
//+------------------------------------------------------------------+
   if(SellOrdersEnabled==true)
     {
      if(BuyCount==0 && SellCount<1)
        {
         if(myOrderType==1)
           {
            double SellOpenPrice=Bid;
            if(StopLoss>0)
              {
               SellStopLoss=SellOpenPrice+(StopLoss*UsePoint);
              }
            if(TakeProfit>0)
              {
               SellTakeProfit=SellOpenPrice -(TakeProfit*UsePoint);
              }
            OrderSend(Symbol(),OP_SELL,LotAmount,SellOpenPrice,UseSlippage,
                      SellStopLoss,SellTakeProfit,"sell order",Magic,0,Red);
            OrderSelect(cnt,SELECT_BY_POS);
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==OP_SELL)
              {
               SellOrderOpenPrice=OrderOpenPrice();
              }
            SellMartingaleFirst=true;
            SellScaleFirst=true;
           }
        }
     }
//+------------------------------------------------------------------+
//| First Sell Martingale                                              |
//+------------------------------------------------------------------+
   if(SellCount>0)
     {
      if(FirstMartingaleEnable==true && SellMartingaleFirst==true)
        {
         if((Bid-SellOrderOpenPrice)>=(FirstMartingalePips*UsePoint))
           {
            FirstSellMartingaleOpen=Bid;
            Print(" --- TEST LINE 1 --- SellOpen of ",Bid," - ",SellOrderOpenPrice,Bid," = ",
                  Bid-SellOrderOpenPrice);
            Print(" --- TEST LINE 2 --- SellMartingalePips of ",FirstMartingalePips," * UsePoint",UsePoint,
                  " = ",(FirstMartingalePips*UsePoint));
            if(StopLoss>0)
              {
               fmSellStopLoss=FirstSellMartingaleOpen+((StopLoss-5-FirstMartingalePips)*UsePoint);
              }
            if(TakeProfit>0)
              {
               fmSellTakeProfit=FirstSellMartingaleOpen -(TakeProfit*UsePoint);
              }
            OrderSend(Symbol(),OP_SELL,LotAmount*FirstMultiplier,FirstSellMartingaleOpen,UseSlippage,
                      fmSellStopLoss,fmSellTakeProfit,"Sell Order",Magic,0,Blue);
            SellMartingaleFirst=false;
            SellMartingaleSecond=true;
           }
        }
     }
//+------------------------------------------------------------------+
//| Second Sell Martingale                                           |
//+------------------------------------------------------------------+
   if(SecondMartingaleEnable==true && SellMartingaleSecond==true)
     {
      if((Bid-SellOrderOpenPrice)>=(SecondMartingalePips*UsePoint))
        {
         double SecondSellMartingaleOpen=Bid;

         if(StopLoss>0)
           {
            smSellStopLoss=SecondSellMartingaleOpen+((StopLoss-5-SecondMartingalePips)*UsePoint);
           }
         if(TakeProfit>0)
           {
            smSellTakeProfit=SecondSellMartingaleOpen -(TakeProfit*UsePoint);
           }
         OrderSend(Symbol(),OP_SELL,LotAmount*SecondMultiplier,SecondSellMartingaleOpen,UseSlippage,
                   smSellStopLoss,smSellTakeProfit,"Sell Order",Magic,0,Magenta);
         SellMartingaleSecond=false;
        }
     }
Ubzen
Moderator
5394
Ubzen 2014.02.17 07:07  
krystalskull:

My EA performs as it should during Strategy tester (in visual mode), but when used on a demo chart it places martingale trade too early.

Strategy: Sell order is placed when conditions are met, then when price goes higher (and trade is negative) the EA is meant to place a martingale trade at the specified amount of pips

above the original sell order open price.

However, when used on a demo account (Alpari) as soon as the first sell order is placed the martingale is placed also at the same time.

It is also doing the same for the second martingale.

Has anyone seen this issue before?

I'm using Build 600.

What does your print statements show?

Are you adjusting for 4/5 digits brokers?

            Print(" --- TEST LINE 1 --- SellOpen of ",Bid," - ",SellOrderOpenPrice,Bid," = ",
                  Bid-SellOrderOpenPrice);
            Print(" --- TEST LINE 2 --- SellMartingalePips of ",FirstMartingalePips," * UsePoint",UsePoint,
                  " = ",(FirstMartingalePips*UsePoint));
krystalskull
22
krystalskull 2014.02.17 08:13  

Print Test Lines from the strategy tester Journal:

2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: open #35 sell 0.60 GBPUSD at 1.55635 sl: 1.56285 tp: 1.54635 ok
2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: --- TEST LINE 2 --- SellMartingalePips of 30 * UsePoint0.0001 = 0.003
2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: --- TEST LINE 1 --- SellOpen of 1.55635 - 1.552221.55635 = 0.004129999999999967
2014.02.17 18:00:53.233 2013.04.30 10:05 ks_COG_EA v2.09 GBPUSD,H4: open #34 sell 1.20 GBPUSD at 1.54701 sl: 1.56251 tp: 1.53701 ok


Print Test Lines from the Demo Journal:

2014.02.17 18:03:00.373 ks_COG_EA v2.09 USDCAD,M1: open #175042095 sell 0.40 USDCAD at 1.09756 sl: 1.10109 tp: 1.08759 ok
2014.02.17 18:02:59.141 ks_COG_EA v2.09 USDCAD,M1: open #175042090 sell 0.20 USDCAD at 1.09756 sl: 1.10409 tp: 1.08759 ok
2014.02.17 18:02:57.753 ks_COG_EA v2.09 USDCAD,M1: --- TEST LINE 2 --- SellMartingalePips of 30 * UsePoint0.0001 = 0.003
2014.02.17 18:02:57.753 ks_COG_EA v2.09 USDCAD,M1: --- TEST LINE 1 --- SellOpen of 1.09759 - 0.01.09759 = 1.09759
2014.02.17 18:02:57.706 ks_COG_EA v2.09 USDCAD,M1: open #175042086 sell 0.10 USDCAD at 1.09752 sl: 1.10752 tp: 1.08752 ok

Five Digit Conversion code below:

int OnInit()
  {
//---
   UsePoint=PipPoint(Symbol());
   
//---
   return(INIT_SUCCEEDED);
  }


//----------- Pip Calculation
double PipPoint(string Currency)
  {
   double CalcPoint=0.0;
   double CalcDigits=MarketInfo(Currency,MODE_DIGITS);
   if(CalcDigits==2 || CalcDigits==3)
     {
      CalcPoint=0.01;
     }
   else if(CalcDigits==4 || CalcDigits==5)
     {
      CalcPoint=0.0001;
     }
   return(CalcPoint);
  }
Ubzen
Moderator
5394
Ubzen 2014.02.17 08:29  
krystalskull:

Print Test Lines from the strategy tester Journal:

2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: open #35 sell 0.60 GBPUSD at 1.55635 sl: 1.56285 tp: 1.54635 ok
2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: --- TEST LINE 2 --- SellMartingalePips of 30 * UsePoint0.0001 = 0.003
2014.02.17 18:00:53.389 2013.04.30 17:40 ks_COG_EA v2.09 GBPUSD,H4: --- TEST LINE 1 --- SellOpen of 1.55635 - 1.552221.55635 = 0.004129999999999967
2014.02.17 18:00:53.233 2013.04.30 10:05 ks_COG_EA v2.09 GBPUSD,H4: open #34 sell 1.20 GBPUSD at 1.54701 sl: 1.56251 tp: 1.53701 ok


Print Test Lines from the Demo Journal:

2014.02.17 18:03:00.373 ks_COG_EA v2.09 USDCAD,M1: open #175042095 sell 0.40 USDCAD at 1.09756 sl: 1.10109 tp: 1.08759 ok
2014.02.17 18:02:59.141 ks_COG_EA v2.09 USDCAD,M1: open #175042090 sell 0.20 USDCAD at 1.09756 sl: 1.10409 tp: 1.08759 ok
2014.02.17 18:02:57.753 ks_COG_EA v2.09 USDCAD,M1: --- TEST LINE 2 --- SellMartingalePips of 30 * UsePoint0.0001 = 0.003
2014.02.17 18:02:57.753 ks_COG_EA v2.09 USDCAD,M1: --- TEST LINE 1 --- SellOpen of 1.09759 - 0.0 1.09759 = 1.09759 <--That 0.0 is suppose to be your order open price.
2014.02.17 18:02:57.706 ks_COG_EA v2.09 USDCAD,M1: open #175042086 sell 0.10 USDCAD at 1.09752 sl: 1.10752 tp: 1.08752 ok

Five Digit Conversion code below:

The reason its failing is because of this line

OrderSelect(cnt,SELECT_BY_POS);

Your OrderSelect() probably failed. cnt was probably not-a-valid position.

Easier to just use Ticket, you'll need to get the Ticket# from OrderSend().

Always check that OrderSelect worked.

Example:

if( OrderSelect(Ticket, Select_By_Ticket) ){
        Do_Something ;
} 
/
To add comments, please log in or register