Hi everyone, Just joined today and love the site. My question is from a past post Mike had done regarding his post, "How to create an advanced
MultiCharts EasyLanguage Strategy." I'm using TradeStation and programming a strategy. I actually copied Mike's coding and it's exactly what I'm looking for when it comes to
scaling out, but have added in my own entry criteria, Unfortunately, I have a couple of problems I can't seem to figure out.
1. I have a particular signal that the trade is executed on. Kind of like a trend signal. After all my targets 3 targets are hit, the problem I'm having is, I don't want the strategy to execute another trade on the same trend signal. Once I'm filled on my third target, it will immediately execute another order and most of the time I'm stopped out giving away all the profits I just made. Does anyone know the coding to only allow it to execute one trade per signal?
2. Does anyone know the coding for a start and stop time the strategy will run? Basically just want to trade the morning E Mini S&P session, nothing after lunch.. I've tried to use the following, but not sure where to put it in the code so it functions properly.
input:
begin_time(0929),
end_time(1200);
if time > begin_time and time < end_time then
begin
{--Enter trade criteria here}
{---
EOD liquidation ---}
if time > end_time then
begin
if marketposition > 0 then sell next bar at market;
if marketposition < 0 then buytocover next bar at market;
end;
3. My final question is, what would be the coding for a maximum loss dollar wise per day and a maximum profit per day.. Once either of those are met, the system stops trading. I would need it to take into account any previous days profit or losses as well as calculate the current trade into the total.. Another words, if my max loss were $500 and I'm down $300 and the system executes another trade, it realizes I only have $200 more to go before it stop trading for the day.
If someone could help me with these final touches, I would appreciate it more than you know. I would need the coding and where to put them. Actually, if you could put them in the following code from Mike on June 2011, that would be terrific.
Mikes coding:
Big Mike Trading
June 2011
}
inputs:
smalength ( 200 ),
emalength ( 100 ),
hmalength ( 34 ),
target1 ( 12 ),
target2 ( 12 ),
target3 ( 20 ),
stopsize ( 12 ),
BE2 ( 0 ), // 0=false, 1=true
BE3 ( 0 ); // 0=false, 1=true
vars:
TickSize ( MinMove / PriceScale ),
smav ( 0 ),
emav ( 0 ),
hmav ( 0 ),
t1 ( Target1 * TickSize ),
t2 ( (Target1 + Target2) * TickSize ),
t3 ( (Target1 + Target2 + Target3) * TickSize ),
st1 ( 0 ),
st2 ( 0 ),
st3 ( 0 );
smav = Average(Close, smalength);
emav = XAverage(Close, emalength);
hmav = jtHMA(Close, hmalength);
// open new positions
if MarketPosition = 0 then begin
if smav > smav[1] and emav > emav[1] and hmav > hmav[1] then begin
Buy ("Enter long") 3
Contracts Next Bar At Market;
end;
if smav < smav[1] and emav < emav[1] and hmav < hmav[1] then begin
SellShort ("Enter short") 3 Contracts Next Bar At Market;
end;
end;
// manage open orders
if MarketPosition = 1 then begin
st1 = EntryPrice - (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
if CurrentContracts = 1 then begin
Sell ("Exit l3-c1 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
Sell ("Exit l2-c2 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c2 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
Sell ("Exit l1-c3 Target") 1 Contracts Next Bar At (EntryPrice + t1) Limit;
Sell ("Exit l1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
Sell ("Exit l2-c3 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c3 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
if CurrentContracts = 1 then begin
BuyToCover ("Exit s3-c1 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
BuyToCover ("Exit s2-c2 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c2 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
BuyToCover ("Exit s1-c3 Target") 1 Contracts Next Bar At (EntryPrice - t1) Limit;
BuyToCover ("Exit s1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
BuyToCover ("Exit s2-c3 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c3 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;
Thanks so much in advance
Paul