View Full Version : pyramiding - DollarProfitAndTrigger
RobertH
29th June 2007, 03:00 AM
I’m testing on a single instrument (XJO) and I want TradeSim to make a pyramid entry whenever the risk amount on the trade has returned to zero (i.e. my ExitPrice >= my previous EntryPrice), and I get an entry signal. I have used the following two lines of code in an attempt to achieve this:
ExtFml("TradeSim.EnableTradePyramiding",DollarProfitAndTrigger,1,200);
ExtFml("TradeSim.SetPyramidProfitThresholdDetection",ExitPrice);
Unfortunately this does not provide me with pyramid entries on the dates that I expect. Is there something simple I have misunderstood? If you need further detail I’m happy to send you the full code, trb file, etc.
David Samborsky
2nd July 2007, 03:05 AM
Because you are re-entering a pyramid when you have the combination of an EntryTrigger along with the required profit gain check your EnteryTrigger. Maybe you just need to re-enter on a profit gain only in which case just use the DollarProfit parameter.
Are you using any entry delays ??
It may pay to post all of your code ;)
RobertH
2nd July 2007, 11:58 PM
Hi David
Following is the code - as you can see, I am using an entry delay. All the details for the initial (level 0) entry are exactly as I expect, however the following 5 pyramid entries are happening on the 5 following periods. These 5 periods do meet my “Trigger” criterion, but not necessarily my “DollarProfit” criterion. However there are other weeks later on that also meet my “Trigger” criterion that aren’t identified as pyramid trades.
Also attached is the trade database.
Also, I have just noticed that there are errors appearing in the error log (attached) for each period following the 5 pyramid entries. I don’t see the relevance of these price comparisons.
Also I tried using just “DollarProfit” as you suggested, but got an identical trade database, i.e. the same 5 pyramid entries.
I’ve clearly done something odd here.
period:=15;
atrMultiplier:=2;
volatility:=atrMultiplier*ATR(period);
barStop:=C-volatility;
EntryTrigger:=C>Ref(HHV(C,period),-1);
EntryPrice:=OPEN;
stopLong:=If(L<=PREV,barStop,If(barStop>PREV,barStop,PREV));
ExitTrigger:=L<=Ref(stopLong,-1);
ExitPrice:=If(H<Ref(stopLong,-1),H,If(L>Ref(stopLong,-1),L,Ref(stopLong,-1)));
InitialStop:=Ref(stopLong,-1);
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",1,7,2006);
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml("TradeSim.SetValue",SystemID,0);
ExtFml("TradeSim.EnableTradePyramiding", DollarProfitAndTrigger,1,200);
ExtFml("TradeSim.SetPyramidProfitThresholdDetection",ExitPrice);
ExtFml("TradeSim.RecordTrades","RH XJO Test - v5b",LONG,EntryTrigger,EntryPrice,InitialStop,ExitTrig ger,ExitPrice,START);
David Samborsky
3rd July 2007, 02:31 AM
The entry delay will also incur a delay on all of the pyramid entries and the price filter will alter prices if prices are violated. Is this what you want ??
Also to aid debugging I would suggest the use of the ShowTrades function which will allow you to ovelay the trading data for a given security on its respective chart ??
RobertH
4th July 2007, 06:55 AM
Hi David, thanks for your very helpful response:
The entry delay will also incur a delay on all of the pyramid entries and the price filter will alter prices if prices are violated. Is this what you want ??
Entry Delay - I definitely want the entry delayed on all the pyramid entries - my scan will be run at the end of the week, and my entry will be at open on the following week. This will be the case with the initial entry and the pyramid entries.
Price Filter – I don’t think this matters as I am using an ExitPrice statement which essentially replicates the logic of the Price Filter for the exits; and I believe that using Open as the EntryPrice with EnableDelayOfEntryByOneBar should not cause any issues. Please let me know if I am wrong here.
Also to aid debugging I would suggest the use of the ShowTrades function which will allow you to ovelay the trading data for a given security on its respective chart ??
Thanks David – Your suggestion caused me to upgrade to the latest version (5.4.0 build 728 ) which of course is a good thing! Surprisingly, even though I was running version 4.2.2 which I downloaded only a few weeks ago, the dll that was installed was dated 25/11/04 which would seem to be an incorrect version. Anyway, following the upgrade the new version's ShowTrades function is excellent!
This brings me back to where I started, albeit in a better-informed state! Using the following two lines of code for my pyramids:
ExtFml(“TradeSim.EnableTradePyramiding”,DollarProf itAndTrigger, PROFIT_THRESHOLD,MAXIMUM_PYRAMID_DEPTH);
ExtFml("TradeSim.SetPyramidProfitThresholdDetection",ExitPrice);
results in a pyramid entry whenever ExitPrice >= the ExitPrice for my previous entry + PROFIT_THRESHOLD, and I get an Entry Trigger. This is good but it is not quite what I want.
I want TradeSim to make a pyramid entry whenever the risk amount on the trade has returned to zero (i.e. my ExitPrice >= the EntryPrice for my previous entry), and I get an Entry Trigger. How can I achieve this?
My code follows:
period:=15;
atrMultiplier:=2;
volatility:=atrMultiplier*ATR(period);
barStop:=C-volatility;
EntryTrigger:=C>Ref(HHV(C,period),-1);
EntryPrice:=OPEN;
stopLong:=If(L<=PREV,barStop,If(barStop>PREV,barStop,PREV));
ExitTrigger:=L<=Ref(stopLong,-1);
ExitPrice:=If(H<Ref(stopLong,-1),H,If(L>Ref(stopLong,-1),L,Ref(stopLong,-1)));
InitialStop:=Ref(stopLong,-1);
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.EnableProtectiveStop",0);
ExtFml("TradeSim.SetExitPriceToInitialStop");
ExtFml("TradeSim.ShowTrades",LONG,"XJO");
ExtFml("TradeSim.SetStartRecordDate",1,7,2006);
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml("TradeSim.SetValue",SystemID,0);
ExtFml("TradeSim.EnableTradePyramiding",DollarProfitAndTrigger,250,200);
ExtFml("TradeSim.SetPyramidProfitThresholdDetection",ExitPrice);
ExtFml("TradeSim.RecordTrades","RH XJO Test - v5e",LONG,EntryTrigger,EntryPrice,InitialStop,ExitTrig ger,ExitPrice,START);
David Samborsky
5th July 2007, 03:02 AM
I want TradeSim to make a pyramid entry whenever the risk amount on the trade has returned to zero (i.e. my ExitPrice >= the EntryPrice for my previous entry), and I get an Entry Trigger. How can I achieve this?
I just checked your code out and I do get some Level 1 pyramid entries which satisfy your criteria.
RobertH
5th July 2007, 04:29 AM
Hi David,
My apologies, but I should have been clearer. The latest code, including the lines
ExtFml("TradeSim.EnableTradePyramiding",DollarProfitAndTrigger,250,200);
ExtFml("TradeSim.SetPyramidProfitThresholdDetection",ExitPrice);
does "work" - i.e. the pyramid entries are taken when the ExitPrice exceeds the ExitPrice of the previous entry by 250 points (and there is an EntryTrigger). However, that "250 points" is a value I included for testing purposes only.
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). How do I achieve this?
Thanks, Robert.
David Samborsky
5th July 2007, 12:57 PM
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). How do I achieve this?
Thanks, Robert.
It should work correctly as you specified !!! From document AN-3
ExitPrice
The Profit threshold detection is made by comparing the exit price specified by the ExitPrice array to the previous re-entry price of the pyramid trade. Note that the base pyramid or level ‘0’ trade always enters at the price specified by the EntryPrice array and new pyramid trades enter at the price specified by the ExitPrice array.
RobertH
11th July 2007, 04:56 AM
Hi David,
I think you've hit on the issue. As you indicated, the doco states "... and new pyramid trades enter at the price specified by the ExitPrice array."
Therefore to clarify my aim, I should add to my previous comment, which read:
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). How do I achieve this?
to instead read:
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). I also want to enter the pyramid trades at the price specified by my EntryPrice array, not my ExitPrice array. How do I achieve this?
Thanks, Robert.
David Samborsky
15th July 2007, 03:57 AM
Hi David,
I think you've hit on the issue. As you indicated, the doco states "... and new pyramid trades enter at the price specified by the ExitPrice array."
Therefore to clarify my aim, I should add to my previous comment, which read:
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). How do I achieve this?to instead read:
But for my pyramid entries I actually want the current ExitPrice to exceed the EntryPrice of the previous entry (and for there to be an EntryTrigger). I also want to enter the pyramid trades at the price specified by my EntryPrice array, not my ExitPrice array. How do I achieve this?
Thanks, Robert.
Currently the only way to re-enter the pyramid at the price specified by the EntryPrice array is to use the EntryPrice profit threshold detection. However this uses the EntryPrice to measure the profit threshold and not the ExitPrice.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.