NexusFi: Find Your Edge


Home Menu

 





Can someone translate this tradestation strategy into an MT4 EA?


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,534 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
warrenpuffit
orlando/florida/usa
 
Posts: 3 since Sep 2011
Thanks Given: 0
Thanks Received: 1

NexusFi (formerly BMT) users,

I recently had a friend ask me to look at his automated strategy idea. I coded it quite easily in tradestation, but he uses MT4. I kind of got in over my head... the translation didnt go very far. if someone has the time, i would love to help them out with anything tradestation related...

Its basically averaging down up to 5 times with a 7.5 pip take profit. If i get below a ceratin loss while all in 5 times, i have a "hedge" put in, flip and double down.... this is how i had Tradestation understand it

 
Code
inputs: 
	PriceH( High ),  
	PriceL( Low ), 
	PriceC( Close ), 
	StochLength( 14 ), 
	SmoothingLength1( 3 ), { used to slow FastK to FastD = SlowK }
	SmoothingLength2( 3 ), { used to slow FastD to SlowD }
	SmoothingType( 1 ), { pass in 1 for Original, 2 for Legacy }
	OverSold( 20 ), 
	OverBought( 80 ) ; 

variables:
	oFastK( 0 ), 
	oFastD( 0 ), 
	oSlowK( 0 ), 
	oSlowD( 0 ) ;

Value1 = Stochastic( PriceH, PriceL, PriceC, StochLength, SmoothingLength1, 
 SmoothingLength2, SmoothingType, oFastK, oFastD, oSlowK, oSlowD ) ;

////////////////////Data 2 P-SAR///////////////////////
variables: AfStep( 0.02, data2 ), AfLimit( 0.2 ,data2) ; 
variables: oParCl( 0 ,data2), oParOp( 0,data2 ), oPosition( 0,data2 ), oTransition( 0 ,data2) ;

 Value1 = ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) of data2 ; 


//////////////Triggers////////////////////////
Vars: hedgebuy1(false), hedgebuy1lotsize(0), hedgebuy2lotsize(0), hedgebuy2(false);
inputs: takethemoney(75);
Vars: hedgesell1(false), hedgesell2(false), hedgesell1lotsize(0), hedgesell2lotsize(0);
vars: onebuy(false), twobuys(false), threebuys(false), fourbuys(false), fivebuys(false), 
onesell(false), twosells(false), threesells(false), foursells(false), fivesells(false);

If (marketposition=0) and (oParCl < (low data2 )) and (oslowk crosses above 20) and (onebuy=false) then begin
buy ("Buy1") 100000 contracts this bar on close;
onebuy=true;
end;

If  (currentcontracts=100000) and (marketposition=1) and (openpositionprofit<=-200) and (onebuy=true) and (hedgebuy1=false) and (hedgebuy2=false) and 
(hedgesell1=false) and (hedgesell2=false) and (oslowk < 20) and (oParCL<(low data2)) Then begin
buy ("Buy2") 100000 contracts this bar on close;
twobuys=true;
end;

If  (currentcontracts=200000) and (marketposition=1) and (openpositionprofit<=-600) and (hedgebuy1=false) and (hedgebuy2=false) and (hedgesell1=false) 
and (hedgesell2=false) and (oParCl< (Low data2)) and (threebuys=false) and (oslowk < 20) Then begin
buy ("Buy3") 100000 contracts this bar on close;
threebuys=true;
end; 

If (currentcontracts=300000) and (marketposition=1) and (oParCl<(Low data2)) and (openpositionprofit<=-1200) and (hedgebuy1=false) and (hedgebuy2=false) and (hedgesell1=false)
and (hedgesell2=false) and (fourbuys=false) and (oslowk < 20) Then begin
buy ("Buy4") 100000 contracts this bar on close;
fourbuys=true;
end;

If (currentcontracts=400000) and (marketposition=1) and (oParCl< (Low data2)) and (openpositionprofit<=-2000) and (hedgebuy1=false) and (hedgebuy2=false) and (hedgesell1=false) 
and (hedgesell2=false) and (fivebuys=false) and (oslowk < 20) Then begin
buy ("Buy5") 100000 contracts this bar on close;
fivebuys=true;
end;


//hedging losing buy1
vars: hedgebuy1loss(0);

If ( (fivebuys=true) and (oParCl>(high data2)) ) then begin
hedgebuy1= true;
hedgebuy1loss= getpositionopenpl(getsymbolname, getaccountid);
Sell ("close5buys") 500000 contracts this bar on close;
sellshort ("Hedge losing buy") 1000000 contracts this bar on close;
onebuy=false;
twobuys=false;
threebuys=false;
fourbuys=false;
fivebuys=false;
end;

//closing from hedging losing buy1
If ( (hedgebuy1=true) and (hedgebuy2=false) ) then begin
If (getpositionopenpl(getsymbolname,getaccountid)> (-1*hedgebuy1loss+75)) then buytocover ("close hedgebuy1") 10000000 contracts this bar on close;
hedgebuy1=false;
end;

//hedging losing buy2
vars: hedgebuy2loss(0);
If ( (hedgebuy1=true) and (oParCl<(low data2)) ) then begin
hedgebuy2=true;
hedgebuy2loss= getpositionopenpl(getsymbolname, getaccountid);
Buytocover ("closebuyhedge1") 1000000 contracts this bar on close;
Buy ("Hedge losing buy 2") 2000000 contracts this bar on close;
hedgebuy1=false;
end;

//closing from hedging losing buy2
If (hedgebuy2=true) then begin
If (getpositionopenpl(getsymbolname,getaccountid)> (-1*hedgebuy2loss+75)) then sell ("close hedgebuy2") 20000000 contracts this bar on close;
end;
}
///////////////Triggers///////////
If (marketposition=0) and (onesell=false) and (oParCl > (high data2)) and (oslowk crosses below 80) then begin
sellshort ("SellS1") 100000 contracts this bar on close;
onesell=true;
end;

If (currentcontracts=100000) and (marketposition=-1) and (openpositionprofit<=-200) and (hedgebuy1=false) and (hedgebuy2=false)
 and (hedgesell1=false) and (hedgesell2=false) and (oParCl>(high data2)) and (twosells=false) and (oslowk > 80) Then begin
 sellshort ("sellS2") 100000 contracts this bar on close;
twosells=true;
end;

If (currentcontracts=200000) and  (marketposition=-1) and (openpositionprofit<=-600) and (hedgebuy1=false) and (hedgebuy2=false)
 and (hedgesell1=false) and (hedgesell2=false) and (oParCl>(high data2)) and (threesells=false) and (oslowk > 80) Then begin
 sellshort ("sellS3") 100000 contracts this bar on close;
threesells=true;
end;

If (currentcontracts=300000) and (marketposition=-1) and (openpositionprofit<=-1200) and (hedgebuy1=false) and (hedgebuy2=false)
 and (hedgesell1=false) and (hedgesell2=false) and (foursells=false) and (oParCL>(high data2)) and (oslowk > 80) Then begin
 sellshort ("sellS4") 100000 contracts this bar on close;
foursells=true;
end;

If (currentcontracts=400000) and (marketposition=-1) and (openpositionprofit<=-2000) and (hedgebuy1=false) and (hedgebuy2=false) 
and (hedgesell1=false) and (hedgesell2=false) and (fivesells=false) and (oParCL > (high data2)) and (oslowk > 80) Then begin
sellshort ("sellS5") 100000 contracts this bar on close;
fivesells=true;
end;

//hedging losing sell 1
vars: hedgesell1loss(0), hedgesell2loss(0);

If ( (oParCl<(low data2)) and (fivesells=True) ) then begin
hedgesell1= true;
onesell=false;
twosells=false;
threesells=false;
foursells=false;
fivesells=false;
hedgesell1loss= getpositionopenpl(getsymbolname, getaccountid);
buytocover("closeshorts") 500000 contracts this bar on close;
buy ("Hedge losing short") 1000000 contracts this bar on close;
end;

//closing from hedging losing buy1
If ( (hedgesell1=true) and (hedgesell2=false) ) then begin
If (getpositionopenpl(getsymbolname,getaccountid)> (-1*hedgebuy1loss+75)) then sell ("close hedgesell1") 10000000 contracts this bar on close;
hedgebuy1=false;
end;

//hedge losing sell 2 

If ( (hedgesell1=true) and (oParCl>(high data2))) then begin
hedgesell2=true;
hedgesell1=false;
hedgesell2loss= getpositionopenpl(getsymbolname, getaccountid);
Sell ("closesellhedge1") 1000000 contracts this bar on close;
Sellshort ("Hedge sell 2") 2000000 contracts this bar on close;
end;


//closing from hedging losing sell2
If (hedgesell2=true) then begin
If (getpositionopenpl(getsymbolname,getaccountid)> (-1*hedgesell2loss+75)) then buytocover ("close hedgesell2") 20000000 contracts this bar on close;
end;

///Take profit and reset strategies on non hedged trades

vars: openbuys(0), opensells(0);
vars: skipp(0), positions(0);
openbuys=0;
opensells=0;

positions= Getpositionopenpl(getsymbolname, getaccountid);

If ((positions> 75) and (hedgebuy1=false) and (hedgebuy2=false) and (hedgesell1=false) and (hedgesell2=false) ) then begin

skipp=0;

If (onebuy=True) and (skipp=0) then openbuys=openbuys+100000;
If (twobuys=True) and (skipp=0) then openbuys= openbuys+100000;
If (threebuys=True) and (skipp=0)  then openbuys= openbuys+100000;
If (fourbuys=True) and (skipp=0)  then openbuys= openbuys+100000;
If (fivebuys=True) and (skipp=0)  then openbuys= openbuys+100000;
If (onesell=True) and (skipp=0)  then opensells=opensells+100000;
If (twosells=True) and (skipp=0)  then opensells= opensells+100000;
If (threesells=True) and (skipp=0)  then opensells= opensells+100000;
If (foursells=True) and (skipp=0)  then opensells= opensells+100000;
If (fivesells=True) and (skipp=0)  then opensells= opensells+100000;
buytocover ("flatten sells") opensells contracts next bar on open;
sell ("flatten buys") openbuys contracts next bar on open;
onebuy=false;
twobuys=false;
threebuys=false;
fourbuys=false;
fivebuys=false;
onesell=false;
twosells=false;
threesells=false;
foursells=false;
fivesells=false;
hedgesell1=false;
hedgesell2=false;
hedgebuy1=false;
hedgebuy2=false;
end;

if this seems like a lot, but its possible, please email me mike @ schauben .com and we can talk about this being a compensated project.

-warrenpuffit


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CFTC Approves First US Bitcoin Perpetual Futures -- Kals …
Traders Hideout
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
TradingView Deploys AI to Monitor SEC Filings in Real Ti …
TradingView
Asia Equities Crash Overnight -- Nikkei -5.2%, KOSPI -6. …
Traders Hideout
Cboe Launches BITVX Bitcoin Volatility Index and Unveils …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
22 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
5 thanks




Last Updated on November 28, 2011


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts