+1 888 340 6572 



Post new topic Reply to topic 
Dynamic stoploss   [ ]
Author Message
#1 posted 05 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
Hi,
I am trying to apply a dynamic stoploss to my automatic trading strategy. The BollingBand width is used for setting the stoploss. I got this to work. But the problem I am having is that I only want to dynamicly determine what the stoploss must be, at the pricelevel at which the position is taking.

As it is now the stoploss is changing whenever the bollingband width is changing. How can I change in Easy Language that it will use the dynamic determined stoploss, as an fixed stoploss once the position is taken.

My code for the stoploss:

Code:
inputs:RiskRewardAmt(2)
          StockAmt(2500)
Variables: Stopvalue(0)

Stopvalue = (StockAmt * (Topband-Bottomband))/RiskRewardAmt);

SetStopLoss(Stopvalue);


Hope someone can give me a idea how to achief this. Thanks!


#2 posted 05 Mar 2012 

Status: Offline
Posts: 148
Thanks Received: 41 times
Thanks Given: 8 times
Joined: 25 Mar 2011
See if this works:

evdl wrote:
How can I change in Easy Language that it will use the dynamic determined stoploss, as an fixed stoploss once the position is taken.

inputs:RiskRewardAmt(2)
StockAmt(2500)
Variables: Stopvalue(0)

if <your buy condition> then
Once Stopvalue = (StockAmt * (Topband-Bottomband))/RiskRewardAmt);

SetStopLoss(Stopvalue);


#3 posted 05 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
Hi Escamillo,

That is a really fast reply! Thanks.

I just tried your suggestion. But that results unfortunatly in no stoploss at all. I put the stoploss code in the condition. Do you have any other suggestions?


#4 posted 05 Mar 2012 

Status: Offline
Posts: 148
Thanks Received: 41 times
Thanks Given: 8 times
Joined: 25 Mar 2011
evdl wrote:
Do you have any other suggestions?


Maybe try it with (where MP = MarketPosition):

if MP[1] = 0 and MP[0] <> 0 then
Once Stopvalue = (StockAmt * (Topband-Bottomband))/RiskRewardAmt);

That method works for me on creating a value when an order is filled. That is all that I can think of for now. Someone hopefully will have an idea. Good luck.



For this message the author escamillo has received thanks:
evdl


#5 posted 05 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
Tried your last suggestion. I put the code in the condition and I also tried it, out of the condition. But the stoploss is not applied.

Thanks for your suggestions.

Does someone have any idea how to solve this?


#6 posted 05 Mar 2012 

Status: Offline
Posts: 228
Thanks Received: 41 times
Thanks Given: 50 times
Joined: 21 May 2009
I can think of this(not tested):

Code:
// If Flat reset StopValue to '0'
if MP[0]=0 and StopValue<>0 then begin
    StopValue=0;
end;

// If Not Flat and Current StopValue=0 then Set the StopValue to required Value
if MP[0]<>0 and StopValue=0 then begin
   Stopvalue = (StockAmt * (Topband-Bottomband))/RiskRewardAmt);
end;


#7 posted 06 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
Hi Vking,

Changed the strategy, but can't get the dynamic stoploss to hold the pricevalue of the moment the position is taken. If I put the code in the condition, then there is no stoploss applied. If I put the code outside the condition, the stoploss will change every bar according to the bandwidth at that moment. The code "once"in front of it, will does not work and will result in no stoploss.

But thanks for your suggestion.


#8 posted 06 Mar 2012 

Status: Offline
Posts: 228
Thanks Received: 41 times
Thanks Given: 50 times
Joined: 21 May 2009
evdl - Can you post the code sample including the buy entry ( you can take out the stuff that you don't want to post) but a sample. That should give an idea on why this is not working for you.

Thanks.


#9 posted 07 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
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;


#10 posted 07 Mar 2012 

Status: Offline
Posts: 228
Thanks Received: 41 times
Thanks Given: 50 times
Joined: 21 May 2009
Can you try this(moved couple of lines - haven't tested):

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 begin
            Buy ("Long") next bar at market;
            Stopvalue = (StockAmt * (Value6/100))/RiskRewardAmt;   
      Profitvalue = (StockAmt * (Value6/100)*0.75);
         end;   
   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;



For this message the author vking has received thanks: 2
evdl, JoshM


#11 posted 08 Mar 2012 

Status: Offline
Posts: 276
Thanks Received: 88 times
Thanks Given: 63 times
Joined: 19 Jan 2011
Hello Vking,

The last suggestion worked! I did put the profitvalue outside the condition so it will use the current bandwidth for profit taking. (Is good for breakouts in the right direction). And the stoploss value is the value when the position was taken.

Thanks for this and your time.



For this message the author evdl has received thanks:
vking


#12 posted 08 Mar 2012 

Status: Offline
Posts: 228
Thanks Received: 41 times
Thanks Given: 50 times
Joined: 21 May 2009
Thanks for the update evdl :)



Post new topic Reply to topic