stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Why won't this work?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5926
Page 1 of 1
Author:  chiefkeef [ Wed Sep 16, 2020 9:54 pm ]
Post subject:  Why won't this work?

My code is meant to buy when stochastic is below 20 and price is above Parabolic SAR. Hwoever, it does not do this. Please help me, I am sure there is a simple reason why it isn;t doing this :).

Code: Select all

void OnTick()

{
double parabolic = iSAR(_Symbol,_Period,0.02,0.2,0);
double KLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_MAIN,0,0);
double DLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_SIGNAL,0,1);

 
  
if (OrdersTotal() == 0)
{  
if(KLine < 20 && Ask > parabolic)
{
OrderSend(_Symbol,OP_BUY,0.1,Ask,3,Ask-50*_Point,Ask+25*_Point,NULL,0,0,Green);
}
}


}
Author:  SteveHopwood [ Thu Sep 17, 2020 3:13 pm ]
Post subject:  Why won't this work?

I do not see why it is not working.

Add some temporary alerts so you can check the return values of the variables. Add some error trapping to the OrderSend() call in case there is something wrong there. The commented out Alert would need adapting for you to use.

Something like this:

Code: Select all

   double parabolic = iSAR(_Symbol,_Period,0.02,0.2,0);
   double KLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_MAIN,0,0);
   double DLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_SIGNAL,0,1);
   
   Alert(parabolic);
   Alert(KLine);
   Alert(DLine);

   RefreshRates();
   bool result = OrderSend(_Symbol,OP_BUY,0.1,Ask,3,Ask-50*_Point,Ask+25*_Point,NULL,0,0,Green);
   if(!result)
   {
      int err=GetLastError();
      if(err==132)//Market is closed
         return;
      //Alert(symbol," Buy: Lots ",lot,": Price ",price,": Ask ",ask, ": Stop ", DoubleToStr(stop, digits), ": take ", DoubleToStr(take, digits) );
      Alert(symbol," ",WindowExpertName()," order send failed with error(",err,"): ",ErrorDescription(err));
      
   }//if (!result)
Bear in mind that OrdersTotal() applies to all orders on the platform, so the conditional will prevent more trades from being sent even if the trades are on a different pair. You might need a function instead that checks to see that there are no open orders on the chart symbol.

:xm: :rocket:
Author:  chiefkeef [ Thu Sep 17, 2020 9:17 pm ]
Post subject:  Why won't this work?

Thanks, for teaching me that ordersend fact!
Author:  SteveHopwood [ Thu Sep 17, 2020 9:55 pm ]
Post subject:  Why won't this work?

chiefkeef ยป Thu Sep 17, 2020 9:17 pm wrote:Thanks, for teaching me that ordersend fact!
There are people here with stunning amounts of stuff that we have leaned.

We all started knowing nothing.

A long time ago, but there really was a time when we knew nothing.

So keep on hacking away at this stuff. You will not be sorry eventually that you did.

:clap: :rocket:
All times are UTC Page 1 of 1