![]() |
|
|||||||
| The Coders Corner This is the place to post your Vitamin-C scripts and share them with others |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|