Condition based on iForce of previously closed candle

 

Hi All,

 I have trouble applying a condition to the iForce value of the previously closed candle. Below you will find how I get the force variables.

 I tried printing myForce[0], myForce[1] and myForce[2] but myForce[0] corresponds to two candles in the past and not the previously closed candle.

 Changing the ForceHandle to us 0,0,3 returns a myForce[0] that does not correspond to anything : ( 

 

 Let me know if I'm not clear and thank you for your help! 

 

//--- Get handle for the FORCE
   ForceHandle=iForce(NULL,0,ForcePeriod,MODE_SMA,VOLUME_TICK);
//--- Copy the new values of our indicators to buffers (arrays) using the handle 
   if(CopyBuffer(ForceHandle,0,1,3,myForce)<0)
     {
      Alert("Error copying Force indicator buffer - error:",GetLastError());
      ResetLastError();
      return;
     }
   bool Buy_Condition_3 = (myForce[1]<300);   
  Print(TimeCurrent()," Print Force ",myForce[0]," - ",myForce[1]," - ",myForce[2]);

 

 

 

Try this code:

//+------------------------------------------------------------------+
//|                                               Previous Force.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
   int ForcePeriod = 14;
   double myForce[];
   ArraySetAsSeries(myForce,true); 
   int ForceHandle=iForce(NULL,0,ForcePeriod,MODE_SMA,VOLUME_TICK);

   if(CopyBuffer(ForceHandle,0,0,3,myForce)<0)
   {
      Alert("Error copying Force indicator buffer - error:",GetLastError());
      ResetLastError();
      return;
   }    

   Print("Previously closed bar Force = ", DoubleToString(myForce[1],_Digits), " Current Force =  ", DoubleToString(myForce[0],_Digits));
   
}
//+------------------------------------------------------------------+
 

Do you see where the change?

in

if(CopyBuffer(ForceHandle,0,0,3,myForce)<0)
 
YES !!! Thanks a lot this did the trick :)
 
codersguru:

Do you see where the change?

in

He already done that (see his first comment)

wiptheman 2013.02.07 18:22

 Changing the ForceHandle to us 0,0,3 returns a myForce[0] that does not correspond to anything : ( 

...

I think this is the one which did the trick

ArraySetAsSeries(myForce,true); 
 

Phi.nuts

Yes you are right  I was missing the ArraySetAsSeries

Reason: