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 PSAR///////////////////////
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;
