Modify stop loss every bar with onBar() method
Modify stop loss every bar with onBar() method
06 Feb 2016, 20:47
I would like to update the stop loss on my position every bar to equal a overlay indicator such as ichimoku kijunsen.
I tried to make it work but it seems to not update every bar, wondering if im missing something.
So my code goes like
protected override void OnBar()
{
double StopLoss = Math.Abs(ichimoku.KijunSen.Last(1) - longPosition.EntryPrice) / Symbol.PipSize;
if( LongPosition != null)
{
ModifyPosition(longPosition, StopLoss, null);
}
if(ShortPosition!= null)
{
ModifyPosition(shortPosition,StopLoss,null);
}
}
//////
Any help will be greatly appreciated. Thanks!
Replies
RodMar
11 Feb 2016, 01:09
RE:
Shawn_Mapilot said:
I would like to update the stop loss on my position every bar to equal a overlay indicator such as ichimoku kijunsen.
I tried to make it work but it seems to not update every bar, wondering if im missing something.
So my code goes like
protected override void OnBar()
{double StopLoss = Math.Abs(ichimoku.KijunSen.Last(1) - longPosition.EntryPrice) / Symbol.PipSize;
if( LongPosition != null)
{
ModifyPosition(longPosition, StopLoss, null);
}
if(ShortPosition!= null)
{
ModifyPosition(shortPosition,StopLoss,null);
}
}
//////
Any help will be greatly appreciated. Thanks!
Try to start "OnBar()" inside "OnStart()". Like this: protected override void OnStart() { ... .... .... OnBar(); }
Perhaps it works.
J. Martins
@RodMar
@fxstarforex
07 Feb 2016, 23:02 ( Updated at: 15 Jan 2024, 14:51 )
:)
Hi, look at this cBot [/algos/cbots/show/1077] there is what You need.
Shawn_Mapilot said:
@@fxstarforex