I've owned a lifetime license for Multicharts for many years, but I've never ask access to the forum until now, so this is my first post. I hope you can kindly assist me.
I've been using Adaptrade Builder for several years solely for study purposes (I've conducted more than 50,000 tests), and now it's time to transition to real trading (with Multicharts plus Interactive Brokers).
My plan is to manage the trading systems generated by Adaptrade Builder with an overall profit target for each system. Essentially, I want to calculate an expected profit for each system I choose to trade in real markets, and when this profit target is achieved (either with a single trade or with the cumulative result of multiple trades potentially spanning in multiple trading days), I want the system to automatically stop trading.
It's important to note that I don't want this global profit target to be calculated in real-time while a trade is in progress. Instead, I'd like it to be determined at the conclusion of the last trade that results in a profit (i.e., accounted trade). This means that the actual profit earned might exceed the expected target. Therefore, I'd like this overall profit target to be calculated based on the series of recorded trades (accounted trades): depending on the market scenario, this could involve a single trade reaching the profit target or multiple trades occurring over several trading days.
For example, if I expect a profit of "n" for System X, and the last completed/accounted trade for this trading system results in a total profit greater than or equal to "n" (generated either by a single trade or by the cumulative result of multiple trades potentially spanning in multiple trading days), I want the system to automatically stop trading.
The same principle applies to the stop-loss strategy.
Unfortunately, I'm not familiar with Easy Language, so I kindly request if you could provide me with the necessary lines of code to achieve what I want and specify at which point in the code generated by Adaptrade Builder I should add these code lines.
So my request is
1) The lines of code necessary to achieve what I have requested
2) And so, taking this randomly selected Trading System code generated by Adaptrade Builder as an example like that:
Code: Select all
{-------------------------------------------------------------------------------
Trading Strategy Code
Population member: 2237
Max bars back: 81
Created by: Adaptrade Builder version 4.4.0.0
Created: 20/06/2023 07:39:21
Scripting language: TS 6 or newer
Symbol: Fake micro-s&p500-60min-10yr (Intraday, 60 min bars), Primary (Data1)
(C:\Program Files\Adaptrade Software\Data\Builder-Stock-60min-10yr.csv)
Build dates: 02/01/2001 to 11/07/2006
Project file: C:\Users\Utente\Desktop\TRADING LAVORO\TESTs Adaptrade Builder\TEST ADAPTRADE BUILDER 4\ACTUAL 2 FAKE sp500\BASIC+3sub_3sub_scelta_alto potenziale_ma da verifcarne consistenza+Crossover 50_Mutation 100.gpstrat
-------------------------------------------------------------------------------}
{ Strategy inputs }
Inputs: NBarEntL1 (81), { Indicator look-back length (bars), long trades }
NStdEntL1 (-1.319498), { Number of standard deviations, long trades }
EntPtsL (0.250000), { Number of points for stop price, long trades }
EntrySzS (0), { Value of fixed size entry (stop/limit) per share/contract, short trades }
NBarExS1 (81), { Number of bars from entry for market exit, short trades }
TargPctS (9.197), { Value of percentage exit target, short trades }
PSParam (1.00), { Position sizing parameter value }
RoundPS (true), { Round-to-nearest (true/false) }
RoundTo (1), { Round-to position size value }
MinSize (1), { Minimum allowable position size }
SizeLimit (100); { Maximum allowable position size }
{ Variables for entry and exit prices }
Var: EntPrL (0),
EntPrS (0),
TargPrS (0);
{ Variables for entry and exit conditions }
Var: VarL1 (0),
VarL2 (0),
EntCondL (false),
EntCondS (false),
ExCondL (false);
{ Variables for position sizing }
Var: NShares (0);
{ Entry prices }
EntPrL = BollingerBand(C, NBarEntL1, NStdEntL1) + EntPtsL;
EntPrS = C + EntrySzS/BigPointValue;
{ Entry and exit conditions }
VarL1 = OpenD(0);
VarL2 = LowD(0);
EntCondL = VarL1 > H;
EntCondS = true;
ExCondL = VarL2 = H;
{ Position sizing calculations }
NShares = PSParam;
If RoundPS and RoundTo > 0 then
NShares = IntPortion(NShares/RoundTo) * RoundTo;
NShares = MaxList(NShares, MinSize);
NShares = MinList(NShares, SizeLimit);
{ Entry orders }
If MarketPosition = 0 and EntCondL and C < EntPrL then begin
Buy("EnStop-L") NShares shares next bar at EntPrL stop;
end;
If MarketPosition = 0 and EntCondS and C < EntPrS then begin
Sell short("EnLimit-S") NShares shares next bar at EntPrS limit;
end;
{ Exit orders, long trades }
If MarketPosition = 1 then begin
If ExCondL then
Sell("ExMark-L") next bar at market;
end;
{ Exit orders, short trades }
If MarketPosition = -1 then begin
TargPrS = (1 - TargPctS/100.0) * EntryPrice;
Buy to cover("ExTarg-S") next bar at TargPrS limit;
If BarsSinceEntry >= NBarExS1 then
Buy to cover("ExMark-S") next bar at market;
end;
Thank you for any guidance or assistance you can provide on achieving this setup.
Best regards, Gian Maria Rossi