Hey guys, having a tough time sorting this one out, been at it a couple days now lol..
No matter which way i right the if statement i always end up with a zero divide, the error messages always seem to point back to the initial calculation itself (buyriskreward or sellriskreward).
I guess i should mention im just trying to create a risk to reward filter, anything above 1:1.5 i want to take a trade, any help is greatly appreciated!
here's the code
use the debugger and set a break point before the calculation line. Then you can examine the values of the variables and understand where your problem is.
use the debugger and set a break point before the calculation line. Then you can examine the values of the variables and understand where your problem is.
Hey guys, having a tough time sorting this one out, been at it a couple days now lol..
No matter which way i right the if statement i always end up with a zero divide, the error messages always seem to point back to the initial calculation itself (buyriskreward or sellriskreward).
I guess i should mention im just trying to create a risk to reward filter, anything above 1:1.5 i want to take a trade, any help is greatly appreciated!
here's the code
//FOR BUYS int buyStopLoss= iLowest(NULL,0,MODE_LOW,CandlesBack,1); int buyTPlevel= iHighest(NULL,0,MODE_CLOSE,TPCandlesBack,1); double buyriskreward =0; double sellriskreward=0; if((Ask - (Low[buyStopLoss])>0 double buyriskreward = ((Close[buyTPlevel]) - Ask) / (Ask - (Low[buyStopLoss])); //FOR SELLS int sellStopLoss= iHighest(NULL,0,MODE_HIGH,CandlesBack,1); int sellTPlevel= iLowest(NULL,0,MODE_CLOSE,TPCandlesBack,1); if((Bid - (Close[sellTPlevel]))>0 sellriskreward = ((High[sellStopLoss]) - Bid) / (Bid - (Close[sellTPlevel])); if(buyriskreward >=1.5 && GapTwo > SmoothedMATen && ParaSar < Bid && OrdersTotal()==0) if(buyriskreward == 0) { Print("Error message:",GetLastError()); ResetLastError(); } else { EnterTrade(OP_BUY); } if(sellriskreward >= 1.5 && Gaptwo < SmoothedMATen && ParaSar > Ask && OrdersTotal()==0) if(sellriskreward == 0) { Print("Error message:",GetLastError()); ResetLastError(); } else { EnterTrade(OP_SELL); }
Also, if you put any number into a standard calculator and divide by zero, watch what happens :)
All the best,
Yes, I've come to learn and whenever you have an IF/ELSE statement, ALWAYS, print an error code with a GetLastError() function in the ELSE brackets, it will save your sanity! Hope you got it sorted :)
Also, if you put any number into a standard calculator and divide by zero, watch what happens :)
All the best,
whoa, i didn't know that would happen! cool!, ah i havent gotten it sorted yet but i've got a few idea's ive found from looking around, going to write them all down and slowly go through them, noob problems haha. thanks for the feedback


- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys, having a tough time sorting this one out, been at it a couple days now lol..
No matter which way i right the if statement i always end up with a zero divide, the error messages always seem to point back to the initial calculation itself (buyriskreward or sellriskreward).
I guess i should mention im just trying to create a risk to reward filter, anything above 1:1.5 i want to take a trade, any help is greatly appreciated!
here's the code