Hi Vking,
This is my code. This is without the suggestions made in this thread. This code works and gives me a dynamic profit target and dynamic stoploss.
Code:
[IntrabarOrderGeneration = FALSE]
inputs:Begin_time (900),
End_time (1730),
Length (20),
NumStdDevs (2),
Price (Close),
RiskRewardAmt (2),
StockAmt (5000),
ProfittargetAmt (0),
StoplossAmt (0),
TrailingTrigger (100),
TrailingAmt (75);
variables: MidBand (0), StdDev (0), TopBand (0), BottomBand (0),Stopvalue (0), profitvalue (0),VolumeAvg(0), MP(0);
MidBand = AverageFC (Price, Length);
StdDev = StandardDev (Price, Length, 1) * NumStdDevs;
TopBand = MidBand + StdDev;
BottomBand = MidBand - StdDev;
Stopvalue = (StockAmt * (Value6/100))/RiskRewardAmt;
Profitvalue = (StockAmt * (Value6/100)*0.75);
MP = Marketposition;
if TopBand <> BottomBand then begin
Value6 = (Topband - BottomBand)* 100;
If time > begin_time and time < end_time then begin
if Condition1 and Condition5 and Condition7 and condition10 and condition11 then
if MP = 0 then
Buy ("Long") next bar at market;
end;
if ProfitTargetAmt > 0 then
SetProfitTarget(ProfitTargetAmt);
if StopLossAmt > 0 then
SetStopLoss(StopLossAmt);
If StopLossAmt = 0 then
SetStopLoss(Stopvalue);
if TrailingAmt > 0 and openpositionprofit >=TrailingTrigger then
SetDollartrailing(trailingAmt);
If ProfitTargetAmt = 0 then
SetProfitTarget(profitvalue);
End;