Forum for TradeSim Users  

Go Back   Forum for TradeSim Users > Vitamin-C for MetaStock > The Coders Corner

The Coders Corner This is the place to post your Vitamin-C scripts and share them with others

Reply
 
Thread Tools Display Modes
  #1  
Old 21st July 2010, 03:52 AM
Scott Scott is offline
Junior Member
Site Admin
 
Join Date: Nov 2009
Posts: 3
Default Tradesim exit price equals the trailing stop

Hi guys,

I am very new to this so you are going to have to check this out for yourselves.

This is nothing fancy all I did was copy the trailing stop code (TrailingStop.c) in vitamin C and changed the result value to return the Prev price rather than an 0 or 1.

I use this as my exit price in tradesim so when my stop is triggered I exit at my stop value not the open, high, low or close values.

This covers off when you are trading CFD's and have a stop placed on the system. Very similar to the ExtFml("TradeSim.SetExitPriceToInitialStop"); function.

I checked out a few trades and it seemed to return the actual trailing stop value as the exit price.

Happy to get any feedback particularly if their was an easier way. Thanks

I called it "TrailingStopValue.c"

The tradesim code I used was:

ExitTrigger:= ExtFml("VitaminC.CallScript3",
"TrailingStop.c", {Normal Exit Trigger}
"TrailingStop(TRIGGER,LONG)",
Volatility,CLOSE,LOW);

ExitPrice:=ExtFml("VitaminC.CallScript3",
"TrailingStopValue.c", {Normal Exit Price}
"TrailingStop(TRIGGER,LONG)",
Volatility,CLOSE,LOW);


Vitamin C Code - changes in Red:

enum ModeEnum {
BAND,
TRIGGER
};

enum PositionEnum {
LONG,
SHORT
};

void TrailingStop(ModeEnum _Mode,PositionEnum _Position)
{
float Band;
float Prev=0;
float Stop;

if(_Position==SHORT)
Prev=1000000; // need this to initialize properly for short condition

for(int i=0;i<BarCount;i++)
{
if(_Position==LONG) // Long Side
{
Stop=User2[i]-User1[i];
if(User3[i]<=Prev)
{
Band=Stop;
if(_Mode==BAND) // Band
Result[i]=Band;
else // Trigger & return Price
Result[i]=Prev;
}
else
{
if(Stop>Prev) // check for new high
Band=Stop; // move the trailing stop band
else
Band=Prev; // keep it the same as before

if(_Mode==BAND) // Band
Result[i]=Band;
else // Trigger
Result[i]=0;
}
}
else // Short side
{
Stop=User2[i]+User1[i];
if(User3[i]>=Prev)
{
Band=Stop;
if(_Mode==BAND) // Band
Result[i]=Band;
else // Trigger & return Price
Result[i]=Prev;
}
else
{
if(Stop<Prev) // check for new low
Band=Stop; // move the trailing stop band
else
Band=Prev; // keep it the same as before

if(_Mode==BAND) // Band
Result[i]=Band;
else // Trigger
Result[i]=0;
}
}

Prev=Band;

}
}

End vitamin C Code
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:24 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright Compuvision Australia Pty Ltd, 2000-2009, All Rights Reserved