two ma cross condition. thanks

 

Hi, thank you in advance for helping me. I'm new to this. what i want to do is when my ma cross in the 15 minutes the ea will go to another condition 

which is wait for my another ma cross in the 5 minutes chart then the trade will be closed. my code is working if i only have 1 ma cross but if i need to wait for two ma crosses it doesnt. thank you, i really appreciate if you will help me with this. this is only for closing order as i enter my trade manually. thanks.

void OnTick()
  {
  
      //curent chart, current period, 20 candles,no shift, simple, close price
      double SlowMovingAverage15 = iMA(NULL, 15,20,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 20 candles,no shift, simple, close price
      double LastSlowMovingAverage15 = iMA(NULL, 15,20,0,MODE_EMA,PRICE_CLOSE,1);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double FastMovingAverage15 = iMA(NULL, 15,10,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double LastFastMovingAverage15 = iMA(NULL, 15,10,0,MODE_EMA,PRICE_CLOSE,1);
  
      //curent chart, current period, 20 candles,no shift, simple, close price
      double SlowMovingAverage = iMA(NULL, 5,20,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 20 candles,no shift, simple, close price
      double LastSlowMovingAverage = iMA(NULL, 5,20,0,MODE_EMA,PRICE_CLOSE,1);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double FastMovingAverage = iMA(NULL, 5,10,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double LastFastMovingAverage = iMA(NULL, 5,10,0,MODE_EMA,PRICE_CLOSE,1);
      
      //if fastMovingAverage is above
      if ((LastFastMovingAverage15 < LastSlowMovingAverage15)
         &&(FastMovingAverage15 > SlowMovingAverage15))
         
      // Chart Output
         OnTick();
         {
            if ((LastFastMovingAverage > LastSlowMovingAverage)
            &&(FastMovingAverage < SlowMovingAverage))
         
            for (int i= OrdersTotal(); i>=0; i--)
            {
               if (OrderSelect(i = 0, SELECT_BY_POS)== true)
               
               //if (OrderSymbol() == Symbol())
               
               OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, Green );
            }   
         }
      
      //if FastMovingAverage is below
      if ((LastFastMovingAverage15 > LastSlowMovingAverage15)
         &&(FastMovingAverage15 < SlowMovingAverage15))
        
         
      // Chart Output
         OnTick();
         {
            if ((LastFastMovingAverage < LastSlowMovingAverage)
            &&(FastMovingAverage > SlowMovingAverage))
            
         
            for (int c= OrdersTotal(); c>=0; c--)
            {
               if (OrderSelect(c = 0, SELECT_BY_POS)== true)
               
               //if (OrderSymbol() == Symbol())
               
               OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, Red );
            }
         
         }

  }
 
Progmt4:

Hi, thank you in advance for helping me. I'm new to this. what i want to do is when my ma cross in the 15 minutes the ea will go to another condition 

which is wait for my another ma cross in the 5 minutes chart then the trade will be closed. my code is working if i only have 1 ma cross but if i need to wait for two ma crosses it doesnt. thank you, i really appreciate if you will help me with this. this is only for closing order as i enter my trade manually. thanks.

ChatGPT ? 
 

You have already been informed not to call OnTick() from within OnTick() ... Ontick inside void ontick()-manual trade is alrrady open

If this code was indeed generated by ChatGPT, then please know that we can't help you.

 
Daniel Cioca #:
ChatGPT ? 
Its not, i coded it. I learned it by watching on youtube.credit to youutibe creators who help like myself thrugh watching youtube. Through this we can make our own but im still struggling by adding more condition. And forums like this is a step up or another level to really go deep in this matter. and thank you topeople who genuinely help . It really can go along way. Cheers . Thanks
 
Fernando Carreiro #:

You have already been informed not to call OnTick() from within OnTick() ... Ontick inside void ontick()-manual trade is alrrady open

If this code was indeed generated by ChatGPT, then please know that we can't help you.

Thanks, still figuring out how to do it. Can i do it by creating a function outside the void ontick and then inside that function has an ontick() and then call the function from the if condition inside the void ontick(). for the seconditon or ma cross to run when the conditon is met. Or what should i do to make another condition run after the 1st conditon. Thanks.

I know my explanation is confusing. Hopefully you can understand it. Thanks really appreciate. Thanks you so much
 
Progmt4:

Hi, thank you in advance for helping me. I'm new to this. what i want to do is when my ma cross in the 15 minutes the ea will go to another condition 

which is wait for my another ma cross in the 5 minutes chart then the trade will be closed. my code is working if i only have 1 ma cross but if i need to wait for two ma crosses it doesnt. thank you, i really appreciate if you will help me with this. this is only for closing order as i enter my trade manually. thanks.



You are defining a conditions of "If "statement what is

OnTick()

Doing there.? Just remove it ..

After defining a conditions of "

if "next is either Buy" or Sell conditions

Or close conditions..


if ((LastFastMovingAverage15 > LastSlowMovingAverage15)
         &&(FastMovingAverage15 < SlowMovingAverage15))
        
         
 
chukwudi joshua obiekwe #:



You are defining a conditions of "If "statement what is

Doing there.? Just remove it ..

After defining a conditions of "

if "next is either Buy" or Sell conditions

Or close conditions..


Thank you for your reply. after the if statement is another condition which is another ma cross. should i put another if statement and indent it after the first condition so the second condition when it is met will run?.

my concern is after the first condition and then if the code check the second condition and the condition is not yet met, the code might end or not wait for the second condition to happen. Thank you for your help.  hope you can help me further. thanks.

 
Progmt4 #:

Thank you for your reply. after the if statement is another condition which is another ma cross. should i put another if statement and indent it after the first condition so the second condition when it is met will run?.

my concern is after the first condition and then if the code check the second condition and the condition is not yet met, the code might end or not wait for the second condition to happen. Thank you for your help.  hope you can help me further. thanks.

void OnTick()
  {
  
      //curent chart, current period, 20 candles,no shift, simple, close price
      double SlowMovingAverage15 = iMA(NULL, 15,20,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 20 candles,no shift, simple, close price
      double LastSlowMovingAverage15 = iMA(NULL, 15,20,0,MODE_EMA,PRICE_CLOSE,1);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double FastMovingAverage15 = iMA(NULL, 15,10,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double LastFastMovingAverage15 = iMA(NULL, 15,10,0,MODE_EMA,PRICE_CLOSE,1);
  
      //curent chart, current period, 20 candles,no shift, simple, close price
      double SlowMovingAverage = iMA(NULL, 5,20,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 20 candles,no shift, simple, close price
      double LastSlowMovingAverage = iMA(NULL, 5,20,0,MODE_EMA,PRICE_CLOSE,1);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double FastMovingAverage = iMA(NULL, 5,10,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 10 candles,no shift, simple, close price
      double LastFastMovingAverage = iMA(NULL, 5,10,0,MODE_EMA,PRICE_CLOSE,1);
      
      



            for (int i= OrdersTotal(); i>=0; i--)
            {
               if (OrderSelect(i = 0, SELECT_BY_POS)== true)
               
               //if (OrderSymbol() == Symbol())


//if fastMovingAverage is above
      if ((LastFastMovingAverage15 < LastSlowMovingAverage15)
         &&(FastMovingAverage15 > SlowMovingAverage15))
          
         {
            if ((LastFastMovingAverage > LastSlowMovingAverage)
            &&(FastMovingAverage < SlowMovingAverage))
         
               OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, Green );             }            }         //----------------------------------------------------------------------------------------------------------                          for (int c= OrdersTotal(); c>=0; c--)             {                if (OrderSelect(c = 0, SELECT_BY_POS)== true)                               //if (OrderSymbol() == Symbol())
 //if FastMovingAverage is below
      if ((LastFastMovingAverage15 > LastSlowMovingAverage15)
         &&(FastMovingAverage15 < SlowMovingAverage15))
       
         {
            if ((LastFastMovingAverage < LastSlowMovingAverage)
            &&(FastMovingAverage > SlowMovingAverage))
            
               OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, Red );             }                   }   }

whatever you want to code you are right but your code is not properly organize...


1. state order type is your EA closing "buy order" or "sell order" cause with this your code the EA will closing anything it sees.

if(OrderType()==OP_BUY) or

if(OrderType()==OP_SELL)

2. check your loops on order, and organize it well
 
I'm not sure "15" will be understood as the 15 minute timeframe, you should use "PERIOD_M15" constant
 
phade #:
I'm not sure "15" will be understood as the 15 minute timeframe, you should use "PERIOD_M15" constant

👇👇👇 this is loops , organize it well.with places i pointed out for you..

Am not referring to your indicator handlers
And constant used..

for (int i= OrdersTotal(); i>=0; i--)
            {
               if (OrderSelect(i = 0, SELECT_BY_POS)== true)
               
               //if (OrderSymbol() == Symbol())
 
chukwudi joshua obiekwe #:

whatever you want to code you are right but your code is not properly organize...


1. state order type is your EA closing "buy order" or "sell order" cause with this your code the EA will closing anything it sees.

Thank you for your help really appreciate it. The ea i created is to close my manual order and all the order currently when the conditions are met automatically. If i put my loop for closeorder before my condition then it will just close all my oder. Then the purpose of why i would like to create an ea is not met. Thanks