Download MetaTrader 5
To add comments, please log in or register
Add our channel to friends and follow the news!
wiptheman
378
wiptheman 2013.02.07 18:22 

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]);

 

 

Ahmed Soliman
11998
Ahmed Soliman 2013.02.08 00:35  

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));
   
}
//+------------------------------------------------------------------+
Ahmed Soliman
11998
Ahmed Soliman 2013.02.08 00:36  

Do you see where the change?

in

if(CopyBuffer(ForceHandle,0,0,3,myForce)<0)
wiptheman
378
wiptheman 2013.02.09 18:17  
YES !!! Thanks a lot this did the trick :)
phi nuts
2185
phi nuts 2013.02.11 05:08  
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); 
wiptheman
378
wiptheman 2013.02.11 12:47  

Phi.nuts

Yes you are right  I was missing the ArraySetAsSeries

/
To add comments, please log in or register