Recording the Moving Average value at OrderOpenTime

 

Hi

I would like to be able to capture the Moving average value at the time of Order.

I was using ibarshift to convert OrderOpenTime to a bar value to use in iMA, but I have noticed that the MA value continues to calculate until the bar of the timeframe selected closes. Is there a way to prevent this?

ExtZZSwingTF is the timeframe - 15mins in this case.

int total=OrdersTotal(),cnt;
for(cnt=0;cnt<total;cnt++)

   if  ( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)
 &&  OrderMagicNumber()  == MagicNumber                  // my magic number
            &&  OrderSymbol()       == Symbol())
       {        
           //TicketDate=OrderOpenTime();
           //StartTime=TicketDate; 
           TicketNumber=OrderTicket();
           TakeProfit = OrderTakeProfit();
           OOT = OrderOpenTime();
           TicketType=OrderType(); //OP_BUY OP_SELL
           OSL=OrderStopLoss();
           EntryPrice = OrderOpenPrice();
            t = iBarShift(NULL,ExtZZSwingTF,OOT,false);
              MAatOpen = iMA(NULL,ExtZZSwingTF,5,0,0,0,t);
 

simoncs:

I would like to be able to capture the Moving average value at the time of Order.

I was using ibarshift to convert OrderOpenTime to a bar value to use in iMA, but I have noticed that the MA value continues to calculate until the bar of the timeframe selected closes. Is there a way to prevent this?

  1. So capture it at the time you open the order.
  2. Of course, it does. Stopping it would be breaking the indicator.
 

Thanks WHR - I think those are for MQL5?

After a rest, i thought to change the iMA to calculate on Open prices rather than Close. I appreciate it changes the calc of the MA, but for my purposes this is better as then the MA value will be static at the time of entry.

Reason: