How to code? - page 118

 

for CEHansen

Hi,

Inside that the for where you take the bars one by one you have to use i variable everywhere instead of Current. Current is uninitialised so it's 0.

The easyest way to see that is put inside the for at the begining this:

Current = i;

The arrows will appear. Also don't forget to use a bigger value for Sto_Lookback. Mabe 100,1000 or something like that.

P.S Use to make the for like this it is better from my point of view.

for (int i = Sto_Lookback; i >0; i--){

...

}

Because this is the normal way of "bars" comming 0 is the last one. It would save you of some other trubles later. (for example - repainting). Just a thought.

Thanks,

Victor

 
 

Klinger Volume Oscillator

I looked this up, looks like an interesting indicator.

However it relys in part on volume, which is not really available in Forex.

Big Be

 

Order Modify Error 1

On my backtesting I keep getting the occasional "OrderModify error1". From what I can figure it means that there is no change, i.e. OrderModify() arguments are the same that corresponding parameters of the modified order.

This might be due to double comparison issue.

Question is how might I solve this issue?

Here's the area I believe is causing the problem:

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//MoveOnce

if(MoveStopOnce && MoveStopWhenPrice > 0) {

if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {

if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {

OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Point * TrailingStop) {

if(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

} else {

//Close

//+------------------------------------------------------------------+

//| Signal Begin(Exit Sell) |

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//| Signal End(Exit Sell) |

//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//MoveOnce

if(MoveStopOnce && MoveStopWhenPrice > 0) {

if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {

if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {

OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {

if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {

OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

}

}

}

 

Code Question

What does i++ or i-- mean in coding?

Eg: for (int i=5; i>0; i--)

 
matrixebiz:
What does i++ or i-- mean in coding? Eg: for (int i=5; i>0; i--)

It is short hand in C based langauges for incrementing or decrementing a number based variable.

For example in Visual Basic you would have to write.

i = i + 1 to increment the i variable.

however, in C you can simply write i++.

Hope this helps.

Hiachiever

 
hiachiever:
It is short hand in C based langauges for incrementing or decrementing a number based variable.

For example in Visual Basic you would have to write.

i = i + 1 to increment the i variable.

however, in C you can simply write i++.

Hope this helps.

Hiachiever

Thanks,

so if I put if (int i=6; i>0; i++)

it will 'loop' or keep checking value until 6 max? not sure if that is right. What if I use i--? Please clarify

 
matrixebiz:
Thanks,

so if I put if (int i=6; i>0; i++)

it will 'loop' or keep checking value until 6 max? not sure if that is right. What if I use i--? Please clarify

Matrixebiz,

if you want to start at 6 and go back to 0 then use i--

(int i=6; i>0; i--)

This will start at 6, decrement by 1 on each loop for as long as I > 0.

If you want to include 0 then use i>=0.

Cheers,

Hiachiever

 
hiachiever:
Matrixebiz,

if you want to start at 6 and go back to 0 then use i--

(int i=6; i>0; i--)

This will start at 6, decrement by 1 on each loop for as long as I > 0.

If you want to include 0 then use i>=0.

Cheers,

Hiachiever

Ok, so if I put if (int i=6; i>0; i++)

then it will start at 6 then , start over incrementing 1, 2, 3 ... 6, correct?

 
matrixebiz:
Ok, so if I put if (int i=6; i>0; i++) then it will start at 6 then , start over incrementing 1, 2, 3 ... 6, correct?

No quite if what you are wanting to do there is finish at 6.

The the code in this case would be

For (int i=1; i<=6; i++)

This will start at 1 and finish at 6 incrementing by 1 on each loop.

Cheers,

Hiachiever