Adding more contracts  [SOLVED]

Questions about MultiCharts and user contributed studies.
Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Adding more contracts

Postby Spikehog » 17 Nov 2015

I want to add more contracts when the direction is favorable to me. Here is my logic: after a first buy entry is completed, a second buy entry will be added at stop price(entryprice + 65 pips), a third buy entry will be added at stop price(entryprice + 130 pips) and a fourth buy entry will be added at stop price(entryprice + 190 pips). However, it doesn't turn out to be the way I want it. As per the image, 1st entry is at 21650, 2nd entry is at 22020, 3rd entry is at 22003 and the 4th entry was at 21950

Code: Select all

IF MP = 1 and PositionFlag and Date > 1110306 and Time > 0930 and Time < 2300 then Begin
IF currentcontracts = 1 then Buy ("LE2ndEntry") 1 contract next bar at (avgentryprice + 65) stop;
IF currentcontracts = 2 then Buy ("LE3rdEntry") 1 contract next bar at (entryprice(0) + 130) stop;
IF currentcontracts = 3 and (barnumber - PosTradeExitBar(0, 3) > 5) then Buy ("LE4thEntry") 1 contract next bar at (PosTradeEntryPrice(0, 0) + 190) stop;
End;
Attachments
MCforum17112015.PNG
(36.94 KiB) Downloaded 666 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Adding more contracts

Postby Henry MultiСharts » 18 Nov 2015

Hello Spikehog,

Please adjust the code the following way:

Code: Select all

IF MP = 1 and PositionFlag and Date > 1110306 and Time > 0930 and Time < 2300 then Begin
IF currentcontracts = 1 AND avgentryprice<>0 then Buy ("LE2ndEntry") 1 contract next bar at (avgentryprice + 65) stop;
IF currentcontracts = 2 AND entryprice(0)<>0 then Buy ("LE3rdEntry") 1 contract next bar at (entryprice(0) + 130) stop;
IF currentcontracts = 3 and (barnumber - PosTradeExitBar(0, 3) > 5) and (PosTradeEntryPrice(0, 0)<>0 then Buy ("LE4thEntry") 1 contract next bar at (PosTradeEntryPrice(0, 0) + 190) stop;
End;

Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Re: Adding more contracts

Postby Spikehog » 19 Nov 2015

Henry, Thanks for the reply. I have done it according to your suggestion. However, the same entries came out again when I did the backtest. Is it something to do with coding or backtesting?

Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Re: Adding more contracts

Postby Spikehog » 20 Nov 2015

Hello Henry, is there anything to do with intrabarordergeneration?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Adding more contracts

Postby Henry MultiСharts » 20 Nov 2015

Hello Spikehog,

Please send us the following information for analysis of this case to support@multicharts.com:
- workspace you are using;
- in QuoteManager select the symbol you are using, make a right click on it->Export data->Export instrument (with data). Send the Qmd export file;
- in PowerLanguage editor->File->Export->export with dependent functions the studies you are using in the workspaces you are providing. Send the study export file.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Adding more contracts  [SOLVED]

Postby Henry MultiСharts » 27 Nov 2015

Hello Spikehog,

Our engineers have added debugging logic to your code:

Code: Select all

IF MP = 1 and PositionFlag and Date > 1110306 and Time > 0930 and Time < 2300 then Begin
if date=1150916 and time>1448 and time<1500 then
begin
print(datetimetostring(datetime), " ; ", avgentryprice, " ; ", entryprice(0), " ; ", PosTradeEntryPrice(0,0), " ; BAR OPEN: ", open);

IF currentcontracts=1 then print("send BUY next bar order LE2ndEntry at STOP ", avgentryprice + 65);
IF currentcontracts=2 then print("send BUY next bar order LE3rdEntry at STOP ", entryprice(0) + 130);
IF currentcontracts=3 and (barnumber - PosTradeExitBar(0,3) > 5) then print("send BUY next bar order LE4rdEntry at STOP ",PosTradeEntryPrice(0, 0) + 190);
print("---------------");
end;
End;
The following output has been generated:
9/16/2015 2:49:00 PM ; 21650.00 ; 21650.00 ; 21650.00 ; BAR OPEN: 22031.00
send BUY next bar order LE2ndEntry at STOP 21715.00
---------------
9/16/2015 2:50:00 PM ; 21835.00 ; 21650.00 ; 21650.00 ; BAR OPEN: 22020.00
send BUY next bar order LE3rdEntry at STOP 21780.00
---------------
9/16/2015 2:51:00 PM ; 21891.00 ; 21650.00 ; 21650.00 ; BAR OPEN: 22003.00
send BUY next bar order LE4rdEntry at STOP 21840.00
---------------
9/16/2015 2:52:00 PM ; 21905.75 ; 21650.00 ; 21650.00 ; BAR OPEN: 21950.00
The following orders have been generated:
send BUY next bar order LE2ndEntry at STOP 21715.00
send BUY next bar order LE3rdEntry at STOP 21780.00
send BUY next bar order LE4rdEntry at STOP 21840.00
The orders executed at the Open prices of the bars as these prices satisfy the order execution logic.
1st entry is at 21650, 2nd entry is at 22020, 3rd entry is at 22003 and the 4th entry was at 21950
Therefore the signal works as expected.


Return to “MultiCharts”