How to use LongCondition, CheckOpenLong, CheckCloseLong, ShortCondition, CheckOpenShort, CheckCloseShort in CExpertSignal correctly?

 

Hi,

I want to write an EA, that uses long signals only.

So far I succeeded in creating my own indicator and creating long- and short-signals using my own class derived from CExpertSignal.
The long and short signals are generated using LongCondition() and ShortCondition().

However, I want my EA to use long-signals only.
When I run the "Strategy Tester" each time the ShortCondition is fulfilled, the EA closes the long-position and opens a new short-position.
But I want it just to close the long-position and wait for the next LongCondition-Signal for opening an other long-postion.

I think that CheckOpenShort() and CheckCloseLong() will do this.
But I could not get them to work.

Are there any Docs/Samples on this out there? Could not find anything that worked for me :-(

Thanks,
Peter 

 

OK - I think I found it.

In the "OnInit()"-Method of my EA I used this Code  to create the signal and set its parameter:

CExpertSignal *signal=new CExpertSignal;
...
ExtExpert.InitSignal(signal);
signal.ThresholdOpen(Signal_ThresholdOpen);
signal.ThresholdClose(Signal_ThresholdClose);

...

CMyEASignal *filter0=new CMyEASignal;
filter0.MyPeriod(Signal_Periond);

I can not remember where I took this "filter"-Stuff from, but as soon as I changed my code as follows, I was able to use CheckOpenLong, CheckCloseLong, CheckOpenShort and CheckCloseShort as I liked.

CMyEASignal  *signal=new CMyEASignal;
...
ExtExpert.InitSignal(signal);
signal.ThresholdOpen(Signal_ThresholdOpen);
signal.ThresholdClose(Signal_ThresholdClose);
signal.MyPeriod(Signal_Periond);

Now I am able to close my long position, without opening a short in my signal class:

bool CMyEASignal::CheckCloseLong(double &price)
   {
   price=0.0;  //???
   bool  signal=false;                   // Flag for signal
   
   //--- For operation with ticks idx=0, for operation with formed bars idx=1
   int idx=StartIndex();
   
   //--- Get current value of indicator
   double current_Line = IndicatorLine(idx);
   //--- Check if indicator is in the top zone
   if (current_Line > 90)
      {
      signal = true;  
      } 
   
   return signal;
   }


However, I very much appreaciate if anybody could explain how to use the paramteres (price, sl, tp, ...) of the methods:
CeckOpenLong(double& price,double& sl,double& tp,datetime& expiration);
CheckCloseLong(double& price);

For example I did use "price=0.0;" in the example above. I took it from some sample-code, without really understanding what the effect would be?!

Thanks,
Peter 

 
SPeter:

OK - I think I found it.

In the "OnInit()"-Method of my EA I used this Code  to create the signal and set its parameter:

I can not remember where I took this "filter"-Stuff from, but as soon as I changed my code as follows, I was able to use CheckOpenLong, CheckCloseLong, CheckOpenShort and CheckCloseShort as I liked.

Now I am able to close my long position, without opening a short in my signal class:


However, I very much appreaciate if anybody could explain how to use the paramteres (price, sl, tp, ...) of the methods:
CeckOpenLong(double& price,double& sl,double& tp,datetime& expiration);
CheckCloseLong(double& price);

For example I did use "price=0.0;" in the example above. I took it from some sample-code, without really understanding what the effect would be?!

Thanks,
Peter 

lPeter,

The parameters used in CeckOpenLong(double& price,double& sl,double& tp,datetime& expiration) is used to return the value of the parameters so the "framework" can use them to  compose a OrderSend command without analyzing the details of the charts, time series and all its unerlying indicators. It is a type of OOP encapsulation that system designers used to hide the details of the underlying, implementation details.Hopefully this can be helpfu!

Reason: