SHARE
TWEET

Untitled

a guest Sep 19th, 2017 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Trade Every Minute for Test Purposes ///////////////////
  2.  
  3. int AutoTrade = 0;
  4. #define PERCENTSTOP
  5.  
  6. assetList("AssetsIG");
  7.  
  8. function click(int row,int col)
  9. {
  10.     if(!is(RUNNING)) return; // only clickable when session is active
  11.     sound("click.wav");
  12.     string Text = panelGet(row,col);
  13.    
  14.     if(Text == "Auto Off") {
  15.         panelSet(row,col,"Auto On",0,0,0);
  16.         AutoTrade = 1;
  17.     }
  18.     else if(Text == "Auto On") {
  19.         panelSet(row,col,"Auto Off",0,0,0);
  20.         AutoTrade = 0;
  21.     }
  22.     else if(Text == "NFA Off") {
  23.         panelSet(row,col,"NFA On",0,0,0);
  24.         set(NFA);
  25.     }
  26.     else if(Text == "NFA On") {
  27.         panelSet(row,col,"NFA Off",0,0,0);
  28.         reset(NFA);
  29.     }
  30.     else if(Text == "Hedge 0") {
  31.         panelSet(row,col,"Hedge 2",0,0,0);
  32.         Hedge = 2;
  33.     }
  34.     else if(Text == "Hedge 2") {
  35.         panelSet(row,col,"Hedge 4",0,0,0);
  36.         Hedge = 4;
  37.     }
  38.     else if(Text == "Hedge 4") {
  39.         panelSet(row,col,"Hedge 5",0,0,0);
  40.         Hedge = 5;
  41.     }
  42.     else if(Text == "Hedge 5") {
  43.         panelSet(row,col,"Hedge 0",0,0,0);
  44.         Hedge = 1;
  45.     }
  46.     else {
  47.         asset(panelGet(3,0));
  48.         Lots = slider(1);   // get current slider position
  49. #ifdef PERCENTSTOP 
  50.         Stop = Trail = round(0.01*priceClose()*slider(2),PIP);
  51. #else
  52.         Stop = Trail = PIP*slider(2);
  53. #endif
  54.         printf("\n%s %s",Text,Asset);
  55.         if(Text == "Buy Long") {
  56.             enterLong();
  57.         } else if(Text == "Buy Short")
  58.             enterShort();
  59.         else if(Text == "Close Long")
  60.             exitLong(0,0,Lots);
  61.         else if(Text == "Close Short")
  62.             exitShort(0,0,Lots);   
  63.         else if(Text == "Update Stop") {
  64.             exitShort(0,priceClose()+Stop);
  65.             exitLong(0,priceClose()-Stop); 
  66.         }
  67.     }
  68. }
  69.  
  70. function run()
  71. {
  72.     if(is(TRAINMODE))   // generate EXE by clicking on [Train]
  73.         set(EXE);
  74.     if(mode(EXE) && !is(EXE))
  75.         return;
  76.     if(is(TESTMODE)) {
  77.         quit("Click [Trade]!");
  78.         return;
  79.     }
  80.    
  81.     BarPeriod = 1;
  82.     NumYears = 1;
  83.     LookBack = 0;
  84.     Verbose = 15;
  85.     Weekend = 0;
  86.     set(LOGFILE);
  87.     //asset("AAPL");
  88.     asset(Asset);
  89.  
  90.     Lots = slider(1,1,0,20,"Lots",0);
  91. #ifdef PERCENTSTOP 
  92.     Stop = Trail = 0.01*priceClose()*slider(2,0,0,40,"Stop %",0);
  93. #else
  94.     Stop = Trail = PIP*slider(2,0,0,50,"Stop",0);
  95. #endif
  96.  
  97.     brokerCommand(SET_ORDERTEXT,"TradeTest");
  98.  
  99.     if(is(INITRUN)) {
  100.         AutoTrade = 0;
  101.         reset(NFA);
  102.         Hedge = 0;
  103.         panel(9,1,GREY,80);
  104.         panelSet(0,0,"Auto Off",ColorPanel[2],1,4);
  105.         panelSet(1,0,"NFA Off",ColorPanel[2],1,4);
  106.         panelSet(2,0,"Hedge 0",ColorPanel[2],1,4);
  107.         panelSet(3,0,Asset,ColorPanel[2],1,2);
  108.         panelSet(4,0,"Buy Long",ColorPanel[3],1,4);
  109.         panelSet(5,0,"Buy Short",ColorPanel[3],1,4);
  110.         panelSet(6,0,"Close Long",ColorPanel[3],1,4);
  111.         panelSet(7,0,"Close Short",ColorPanel[3],1,4);
  112.         panelSet(8,0,"Update Stop",ColorPanel[3],1,4);
  113.     }
  114.    
  115.     if(AutoTrade) {
  116.         asset(panelGet(3,0));
  117.         if(NumOpenTotal >= 3) {
  118.             exitLong();
  119.             exitShort();
  120.         } else {
  121.             if(price(0) > price(1))
  122.                 enterLong();
  123.             else if(price(0) < price(1))
  124.                 enterShort();
  125.         }
  126.     }
  127. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top