Why won't this work?

Post Reply
chiefkeef
Trader
Posts: 13
Joined: Mon Sep 07, 2020 8:09 pm

Why won't this work?

Post by chiefkeef »

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


}
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Why won't this work?

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
chiefkeef
Trader
Posts: 13
Joined: Mon Sep 07, 2020 8:09 pm

Why won't this work?

Post by chiefkeef »

Thanks, for teaching me that ordersend fact!
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Why won't this work?

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Coders Hangout”