View Full Version : Pyramiding errors
kallie
30th November 2004, 06:40 AM
This is the code for the long side of a system i have been using (on v3.5)before i recently upgraded to v4.2.
when i run this system on v4.2 it gives me about 8000 errors. If i remove the EnableTradePyramiding then it seems to work fine.
The system is suppossed to pyramid in when the trailing stop price=entry price. This would be a breakeven (ie. trailing stop price=entry price)
Every new position must have the typical Initial & Trailing stops as shown in the code.
I have tried to use the new
ExtFml("TradeSim. SetPyramidProfitThresholdDetection",EntryPrice);
but it seems the % profit is measured between the Entry Price & current days Open. Is that correct?
I suppose i need to measure Entry Price - Trailing Stop Price=0.
Can anyone shed any light on it for me please?
Thanks
{=== SET DATE VARIABLES ===}
DayStart := 10; MthStart := 10; YearStart := 1996; DayStop := 10; MthStop := 10; YearStop := 2004;
LongEntryTrigger := Ref(H,-2)<=Ref(H,-1) AND
Ref(Stoch(10,3),-1)>Ref(Stoch(10,3),-2)AND
Ref(ATR(30)/Mov(C,30,S)>0.01,-1) AND
Ref(C>0.5,-1) AND
Ref(Mov(C,50,S) * Mov(V,50,S) > 400000,-1) AND
LLV(L,3) / Ref(O,1) > 0.90;
LongEntryPrice := OPEN;
LongExitTrigger := ExtFml( "TradeSim.TrailingStop",trigger ,long ,5*ATR(10) ,H ,L ) ;
LongExitPrice := Ref(ExtFml( "TradeSim.TrailingStop",band ,long ,5*ATR(10) ,H ,L ),-1) ;
LongExitPrice := If(O<=LongExitPrice,O,LongExitPrice);
LongInitialStop :=Ref(H-2.5*ATR(10),-1);
ExtFml( "TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart);
ExtFml("TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop);
ExtFml( "TradeSim.EnableProtectiveStop",0) ;
ExtFml( "TradeSim.SetExitPriceToInitialStop");
ExtFml( "TradeSim.SetStopGapPriceToOpen");
ExtFml( "TradeSim.EnableTradePyramiding",PercentProfit,0,10);
ExtFml( "TradeSim.RecordTrades","001 System 6v2 - Trend Following",LONG,LongEntryTrigger,LongEntryPrice,LongInitialS top,LongExitTrigger,LongExitPrice,START);
David Samborsky
30th November 2004, 07:18 AM
The most likely cause of all the errors is prices falling outside the daily range.
The quickest way to fix this is to use EnablePriceFilter which forces all prices to lie within the daily range. However further inspection of the formula maybe required to see how you can properly target prices.
kallie
30th November 2004, 10:45 AM
David
What really concerns me is why this code is giving me errors when i wasn't getting errors before. (on the previous version).
Does Tradsim interpret pyramids differently now or is there another reason?
David Samborsky
30th November 2004, 12:12 PM
A bit of work has been done to the pyramid code. Please check the Read Me file regarding pyramids for both TradeSim.exe app and the TradeSim.dll plug-in.
Also I would check the error log as to the reason why the errors are appearing.
kallie
30th November 2004, 11:00 PM
David
I have done quite a bit of work in trying to solve this problem but can not find anything in the manual or release notes that refer to this problem.
I have the trade database for this system (when run on v3...) and it treats 0% rise in position value as being the point when trailing stop=entry price.
Please can you look into this as it is definitly not running like this now and i havn't changed my code.
Additionally i am now left with at trading system i can no long replicate and monitor.
thanks
David Samborsky
1st December 2004, 09:34 AM
I will look into this asap.
kallie
1st December 2004, 11:11 AM
David
I was hoping to recode to achieve the same result. Hence i have used the pyramid trigger below. However it seems to enter a new trade every day (on open).
Can you explain why?
If i want to enter pyramid trades with a stop entry then should i used DailyRange and
If i want to enter pyramid trades on the next days open then should i used EntryPrice?
I'm afraid i'm not 100% clear on the SetPyramidProfitThresholdDetection & i have read the notes.
cheers
{as above}
LongEntryPrice := OPEN;
LongExitTrigger := ExtFml( "TradeSim.TrailingStop",trigger ,long ,5*ATR(10) ,H ,L ) ;
LongExitPrice := Ref(ExtFml( "TradeSim.TrailingStop",band ,long ,5*ATR(10) ,H ,L ),-1) ;
LongExitPrice := If(O<=LongExitPrice,O,LongExitPrice);
LongInitialStop :=Ref(H-2.5*ATR(10),-1);
ExtFml( "TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart);
ExtFml("TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop);
ExtFml( "TradeSim.EnableProtectiveStop",0) ;
ExtFml( "TradeSim.SetExitPriceToInitialStop");
ExtFml( "TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim. SetPyramidProfitThresholdDetection",EntryPrice);
{ExtFml( "TradeSim.EnablePriceFilter") ;}
ExtFml("TradeSim.EnableTradePyramiding",Trigger, 0,4);
EntryTrigger:= Ref(ExtFml( "TradeSim.TrailingStop",band ,long ,5*ATR(10) ,H ,L ),-1)>=LongEntryPrice ;
ExtFml( "TradeSim.RecordTrades","001 System 6v2 - Trend Following",LONG,LongEntryTrigger,LongEntryPrice,LongInitialS top,LongExitTrigger,LongExitPrice,START);
{=== SHORT TRADES ===}
David Samborsky
1st December 2004, 11:44 AM
Ok I have checked it out and I originally thought it was a coding problem in the plugin, then I discovered what was causing the problem.
The problem is caused by your assignement of the LongExitPrice. In some circumstances where the profit threshold is exceeded and the next level pyramid is entered the trade is rejected because in most cases your exit price lies outside the daily range. To prove this temporarily assign the closing price to the ExitPrice and rerun the exploration.
The solution is to use the Price Filter before the call to RecordTrades i.e.,
ExtFml("TradeSim.EnablePriceFilter");
The reason why the previous version worked without producing any errors is because although it used the exit price to determine the profit threshold it would enter the pyramid trade using the entry price so it would could not check for invalid exit prices (until the pyramid was closed). Now with Version 5.2.1 of the plugin the default mode is to use the exit price to determine the profit threshold but enter the trade using the exit price instead of the entry price as was done in previous versions. Only in new version can invalid exit prices be detected whereas previously they would go undetected.
With version 5.2.1 alternatively you can use the entry price to determine the profit threshold and then enter a new pyramid trade using the entry price.
If you download the latest copy of document AN-3 you will discover an additional function called SetProfitThresholdDetection to allow you to more precisely control the way you re-enter trades based on pyramid trade profit re-entry.
If i want to enter pyramid trades with a stop entry then should i used DailyRange and
If i want to enter pyramid trades on the next days open then should i used EntryPrice?
Yes this is correct.
kallie
3rd December 2004, 05:05 AM
David
I have gone through your above sugestions & have tried a number of options. None of which replicate my previous system.
As far as i can see the below code says-
-----ExtFml("TradeSim. SetPyramidProfitThresholdDetection",ExitPrice);
Since the Trailing stop=Exit Price then this code measures the distance in price from the trade Entry Price to the Trailing Stop.
This starts off as a -'ve % and moves up.
----ExtFml("TradeSim.EnableTradePyramiding",PercentProfit, 0,4);
Therefore 0% Increase is breakeven. Hence 0% in the code.
Below is my code for this
Please can you tell me where i'm interpreting this wrong?
thanks
ExtFml( "TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart);
ExtFml("TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop);
ExtFml( "TradeSim.EnableProtectiveStop",0) ;
ExtFml( "TradeSim.SetExitPriceToInitialStop");
ExtFml( "TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim. SetPyramidProfitThresholdDetection",ExitPrice);
ExtFml( "TradeSim.EnablePriceFilter") ;
ExtFml("TradeSim.EnableTradePyramiding",PercentProfit, 0,4);
{Trigger:= Ref(ExtFml( "TradeSim.TrailingStop",band ,long ,5*ATR(10) ,H ,L ),-1)>=LongEntryPrice ;}
ExtFml( "TradeSim.RecordTrades","001 System 6v2 - Trend Following",LONG,LongEntryTrigger,LongEntryPrice,LongInitialS top,LongExitTrigger,LongExitPrice,START);
kallie
3rd December 2004, 05:05 AM
David
I have gone through your above sugestions & have tried a number of options. None of which replicate my previous system.
As far as i can see the below code says-
-----ExtFml("TradeSim. SetPyramidProfitThresholdDetection",ExitPrice);
Since the Trailing stop=Exit Price then this code measures the distance in price from the trade Entry Price to the Trailing Stop.
This starts off as a -'ve % and moves up.
----ExtFml("TradeSim.EnableTradePyramiding",PercentProfit, 0,4);
Therefore 0% Increase is breakeven. Hence 0% in the code.
Below is my code for this
Please can you tell me where i'm interpreting this wrong?
thanks
ExtFml( "TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart);
ExtFml("TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop);
ExtFml( "TradeSim.EnableProtectiveStop",0) ;
ExtFml( "TradeSim.SetExitPriceToInitialStop");
ExtFml( "TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim. SetPyramidProfitThresholdDetection",ExitPrice);
ExtFml( "TradeSim.EnablePriceFilter") ;
ExtFml("TradeSim.EnableTradePyramiding",PercentProfit, 0,4);
{Trigger:= Ref(ExtFml( "TradeSim.TrailingStop",band ,long ,5*ATR(10) ,H ,L ),-1)>=LongEntryPrice ;}
ExtFml( "TradeSim.RecordTrades","001 System 6v2 - Trend Following",LONG,LongEntryTrigger,LongEntryPrice,LongInitialS top,LongExitTrigger,LongExitPrice,START);
David Samborsky
6th December 2004, 07:16 AM
Starting with version 5.0.2 we fixed the way that stops were handled in pyramid trades. Please study the Readme file for more details.
When pyramid trades are enabled and protective stops are enabled if a stop is breached then the trade pyramid is automatically closed. Previously when pyramids were enabled and stops were breached the stop would be ignored and the pyramid would continue until a valid exit trigger was detected.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.