T101 v2.4 ea





//+---------------------------------------------------------------------+
//|                                                    T101 v2.3.mq4    |
//|                                  Copyright © 2008, thomas liles.    |
//|                                       http://www.trendchaser.org    |
//|added code to sort pairs in descending order: guiomdetalle, 28/09/08 |
//+---------------------------------------------------------------------+
#property copyright "Copyright © 2008, thomas liles."
#property link      "http://www.trendchaser.org"
extern bool alert= true;
extern bool can_trade= true;
extern bool counter_trade= false;
extern bool can_exit= true;
extern bool equity_trail= true;
extern double start_trail= 2;
extern double trail= 2;
extern double starting_target=-10;
extern  bool exit_on_reverse= false;
extern double Lot= 0.01;
extern double Maximum_Risk = 0.5;
extern int look_back= 0;
extern int tf=60;
extern bool update_start= false;
extern double pips_filter= 100;
extern string long_basket= "enter 7 long symbols";
extern string long_basket1= "GBPUSDm";
extern double price1= 0;
extern string long_basket2= "EURGBPm";
extern double price2= 0;
extern string long_basket3= "GBPJPYm";
extern double price3= 0;
extern string long_basket4= "USDCHFm";
extern double price4= 0;
extern string long_basket5= "NZDUSDm";
extern double price5= 0;
extern string long_basket6= "AUDJPYm";
extern double price6= 0;
extern string long_basket7= "EURJPYm";
extern double price7= 0;

extern string short_basket= "enter 7 short symbols";
extern string short_basket1= "EURUSDm";
extern double price8= 0;
extern string short_basket2= "USDJPYm";
extern double price9= 0;
extern string short_basket3= "AUDUSDm";
extern double price10= 0;
extern string short_basket4= "NZDJPYm";
extern double price11= 0;
extern string short_basket5= "GBPCHFm";
extern double price12= 0;
extern string short_basket6= "CHFJPYm";
extern double price13= 0;
extern string short_basket7= "EURCHFm";
extern double price14= 0;
extern int profit_font_size =16;

double pcnt;
int prob = 0;
bool longs_allowed=true,short_alert=true,long_alert=true;
bool shorts_allowed=true;
double GBPUSDm,EURGBPm,GBPJPYm,USDCHFm,NZDUSDm,AUDJPYm,EURJPYm;double EURUSDm,USDJPYm,AUDUSDm,NZDJPYm,GBPCHFm,CHFJPYm,EURCHFm;double GBPUSDm_now,EURGBPm_now,GBPJPYm_now,USDCHFm_now,NZDUSDm_now,AUDJPYm_now,EURJPYm_now;double EURUSDm_now,USDJPYm_now,AUDUSDm_now,NZDJPYm_now,GBPCHFm_now,CHFJPYm_now,EURCHFm_now;double GBPUSDm_pips,EURGBPm_pips,GBPJPYm_pips,USDCHFm_pips,NZDUSDm_pips,AUDJPYm_pips,EURJPYm_pips;double EURUSDm_pips,USDJPYm_pips,AUDUSDm_pips,NZDJPYm_pips,GBPCHFm_pips,CHFJPYm_pips,EURCHFm_pips;double highest_long_pips=0, highest_short_pips=0,long_pips, short_pips;string signal;
int gbpusd,eurgbp,gbpjpy,usdchf,nzdusd,audjpy,eurjpy,eurusd,usdjpy,audusd,nzdjpy,gbpchf,chfjpy,eurchf,blue,red,buys,sells;
int init()
{

start();

return(0);
}
int deinit()
{
checkup();
/*
ObjectDelete("1");
ObjectDelete("2");
ObjectDelete("3");
ObjectDelete("4");
ObjectDelete("5");
ObjectDelete("6");
ObjectDelete("7");
ObjectDelete("8");
ObjectDelete("9");
ObjectDelete("10");
ObjectDelete("11");
ObjectDelete("12");
ObjectDelete("13");
ObjectDelete("14");
ObjectDelete("sig");
*/

return(0);
}
int start()
{
if(prob==0) checkup();
if(update_start) checkup();
pcnt =( (AccountEquity()-AccountBalance()) / AccountBalance())*100;
//if (prob==0) {checkup();}
Lot=LotsOptimized();
orders();
if (prob==1&&can_exit){check_exit();}
run_statistics_longs();  
run_statistics_shorts(); 
draw_objects();
if(prob==1)signal = "Ranging";
if (blue >red&&long_pips>pips_filter&&short_pips<pips_filter) {signal = "long";}
if (blue <red&&short_pips>pips_filter&&long_pips<pips_filter) {signal = "short";}

if (long_pips>0&&long_pips<highest_long_pips-pips_filter) {signal = "reversing to shorts";}
if (short_pips>0&&short_pips<highest_short_pips-pips_filter) {signal = "reversing to longs";}

if (long_pips<0 ){highest_long_pips=0;}
if (short_pips<0) {highest_short_pips=0;}


if (prob==1&&can_trade&&signal=="long"){buy();}
if (prob==1&&can_trade&&signal=="short"){sell();}

if (counter_trade&&prob==1&&can_trade&&signal=="reversing to longs"){buy();}
if (counter_trade&&prob==1&&can_trade&&signal=="reversing to shorts"){sell();}

prob=1;
 double g;
   int m,s,k,h;
   m=Time[0]+Period()*60-TimeCurrent();
   g=m/60.0;
   s=m%60;
   m=(m-m%60)/60;
   if(m>=60) h=m/60; else h=0;
   k=m-(h*60);

    datetime m1=Time[0]+Period()*60-TimeCurrent();
     datetime m5=Time[0]+5*60-TimeCurrent();
    datetime m15=Time[0]+15*60-TimeCurrent();
    datetime m30=Time[0]+30*60-TimeCurrent();
    datetime m60=Time[0]+60*60-TimeCurrent();
    datetime m240=Time[0]+240*60-TimeCurrent();
Comment("\n","bar timer= ",TimeToStr(m1,TIME_SECONDS),
"\n","buys= ",buys,
"     sells= ",sells);
    
return(0);
}

void checkup(){
if (price1==0)GBPUSDm= iClose(long_basket1, tf, look_back);else GBPUSDm=price1;
if (price2==0)EURGBPm= iClose(long_basket2, tf, look_back);else EURGBPm=price2;
if (price3==0)GBPJPYm= iClose(long_basket3, tf, look_back);else GBPJPYm=price3;
if (price4==0)USDCHFm= iClose(long_basket4, tf, look_back);else USDCHFm=price4;
if (price5==0)NZDUSDm= iClose(long_basket5, tf, look_back);else NZDUSDm=price5;
if (price6==0)AUDJPYm= iClose(long_basket6, tf, look_back);else AUDJPYm=price6;
if (price7==0)EURJPYm= iClose(long_basket7, tf, look_back);else EURJPYm=price7;
if (price8==0)EURUSDm= iClose(short_basket1, tf, look_back);else EURUSDm=price8;
if (price9==0)USDJPYm= iClose(short_basket2, tf, look_back);else USDJPYm=price9;
if (price10==0)AUDUSDm= iClose(short_basket3, tf, look_back);else AUDUSDm=price10;
if (price11==0)NZDJPYm= iClose(short_basket4, tf, look_back);else NZDJPYm=price11;
if (price12==0)GBPCHFm= iClose(short_basket5, tf, look_back);else GBPCHFm=price12;
if (price13==0)CHFJPYm= iClose(short_basket6, tf, look_back);else CHFJPYm=price13;
if (price14==0)EURCHFm= iClose(short_basket7, tf, look_back);else EURCHFm=price14;}

//+------------------------------------------------------------------+
//|     TC                                lots
//+------------------------------------------------------------------+
double LotsOptimized()
{
double minimum_lots=MarketInfo(Symbol(),MODE_MINLOT);
double max_lots=MarketInfo(Symbol(),MODE_MAXLOT);
double lot=Lot;   

     if (minimum_lots==0.001){ lot=NormalizeDouble(AccountBalance()*Maximum_Risk/1000,3);{}}
     if (minimum_lots==0.01){ lot=NormalizeDouble(AccountBalance()*Maximum_Risk/10000,2);{}}
     if (minimum_lots==0.1){ lot=NormalizeDouble(AccountBalance()*Maximum_Risk/100000,1); {}}  
     if (minimum_lots==1){ lot=NormalizeDouble(AccountBalance()*Maximum_Risk/1000000,0);{}}
     
     if (lot<=minimum_lots){lot  = minimum_lots;{}}
     if (lot>=max_lots){lot  = max_lots;{}}
     if (lot<=Lot){lot  = Lot;{}}      // prevent lots from decreasing
     if (Maximum_Risk==0){lot  = Lot;{}}
return(lot);
}

void orders()
{
 buys=0;sells=0;gbpusd=0;eurgbp=0;gbpjpy=0;usdchf=0;nzdusd=0;audjpy=0;eurjpy=0;eurusd=0;usdjpy=0;audusd=0;nzdjpy=0;gbpchf=0;chfjpy=0;eurchf=0;
  int totalorders = OrdersTotal();
  for(int i=totalorders-1;i>=0;i--)
 {
    OrderSelect(i, SELECT_BY_POS);
           if ( OrderType() == OP_SELL )  {sells=sells+1;}
           if ( OrderType() == OP_BUY )   {buys=buys+1;}
           if ( OrderSymbol() == long_basket1 )  {gbpusd++;}
           if ( OrderSymbol() == long_basket2 )  {eurgbp++;}
           if ( OrderSymbol() == long_basket3 )  {gbpjpy++;}
           if ( OrderSymbol() == long_basket4 )  {usdchf++;}
           if ( OrderSymbol() == long_basket5 )  {nzdusd++;}
           if ( OrderSymbol() == long_basket6 )  {audjpy++;}
           if ( OrderSymbol() == long_basket7 )  {eurjpy++;}
           if ( OrderSymbol() == short_basket1 )  {eurusd++;}
           if ( OrderSymbol() == short_basket2 )  {usdjpy++;}
           if ( OrderSymbol() == short_basket3 )  {audusd++;}
           if ( OrderSymbol() == short_basket4 )  {nzdjpy++;}
           if ( OrderSymbol() == short_basket5 )  {gbpchf++;}
           if ( OrderSymbol() == short_basket6 )  {chfjpy++;}
           if ( OrderSymbol() == short_basket7 )  {eurchf++;}
           if ( OrdersTotal() == 0 )  {starting_target=-10;}
}
return;
}

void buy()
{
if (longs_allowed&&gbpusd==0)OrderSend(long_basket1,OP_BUY, LotsOptimized(), MarketInfo(long_basket1,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&eurgbp==0)OrderSend(long_basket2,OP_BUY, LotsOptimized(), MarketInfo(long_basket2,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&gbpjpy==0)OrderSend(long_basket3,OP_BUY, LotsOptimized(), MarketInfo(long_basket3,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&usdchf==0)OrderSend(long_basket4,OP_BUY, LotsOptimized(), MarketInfo(long_basket4,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&nzdusd==0)OrderSend(long_basket5,OP_BUY, LotsOptimized(), MarketInfo(long_basket5,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&audjpy==0)OrderSend(long_basket6,OP_BUY, LotsOptimized(), MarketInfo(long_basket6,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&eurjpy==0)OrderSend(long_basket7,OP_BUY, LotsOptimized(), MarketInfo(long_basket7,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);

if (longs_allowed&&eurusd==0)OrderSend(short_basket1,OP_BUY, LotsOptimized(), MarketInfo(short_basket1,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&usdjpy==0)OrderSend(short_basket2,OP_BUY, LotsOptimized(), MarketInfo(short_basket2,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&audusd==0)OrderSend(short_basket3,OP_BUY, LotsOptimized(), MarketInfo(short_basket3,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&nzdjpy==0)OrderSend(short_basket4,OP_BUY, LotsOptimized(), MarketInfo(short_basket4,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&gbpchf==0)OrderSend(short_basket5,OP_BUY, LotsOptimized(), MarketInfo(short_basket5,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&chfjpy==0)OrderSend(short_basket6,OP_BUY, LotsOptimized(), MarketInfo(short_basket6,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (longs_allowed&&eurchf==0)OrderSend(short_basket7,OP_BUY, LotsOptimized(), MarketInfo(short_basket7,MODE_ASK), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);

shorts_allowed=true;
return;
}

void sell()
{

if (shorts_allowed&&gbpusd==0)OrderSend(long_basket1,OP_SELL, LotsOptimized(), MarketInfo(long_basket1,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&eurgbp==0)OrderSend(long_basket2,OP_SELL, LotsOptimized(), MarketInfo(long_basket2,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&gbpjpy==0)OrderSend(long_basket3,OP_SELL, LotsOptimized(), MarketInfo(long_basket3,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&usdchf==0)OrderSend(long_basket4,OP_SELL, LotsOptimized(), MarketInfo(long_basket4,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&nzdusd==0)OrderSend(long_basket5,OP_SELL, LotsOptimized(), MarketInfo(long_basket5,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&audjpy==0)OrderSend(long_basket6,OP_SELL, LotsOptimized(), MarketInfo(long_basket6,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&eurjpy==0)OrderSend(long_basket7,OP_SELL, LotsOptimized(), MarketInfo(long_basket7,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);

if (shorts_allowed&&eurusd==0)OrderSend(short_basket1,OP_SELL, LotsOptimized(), MarketInfo(short_basket1,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&usdjpy==0)OrderSend(short_basket2,OP_SELL, LotsOptimized(), MarketInfo(short_basket2,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&audusd==0)OrderSend(short_basket3,OP_SELL, LotsOptimized(), MarketInfo(short_basket3,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&nzdjpy==0)OrderSend(short_basket4,OP_SELL, LotsOptimized(), MarketInfo(short_basket4,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&gbpchf==0)OrderSend(short_basket5,OP_SELL, LotsOptimized(), MarketInfo(short_basket5,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&chfjpy==0)OrderSend(short_basket6,OP_SELL, LotsOptimized(), MarketInfo(short_basket6,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
if (shorts_allowed&&eurchf==0)OrderSend(short_basket7,OP_SELL, LotsOptimized(), MarketInfo(short_basket7,MODE_BID), 2, NULL, NULL, NULL, 0, 0, CLR_NONE);
longs_allowed=true;
return;
}



void check_exit()
{
 

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (equity_trail&&pcnt>=start_trail&&starting_target<pcnt-trail ){starting_target=pcnt-trail;}

if (pcnt<=starting_target&&OrderType() == OP_BUY ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );if (OrdersTotal()==0)starting_target=-10;longs_allowed=false;}
           
if (pcnt<=starting_target&&OrderType() == OP_SELL ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );if (OrdersTotal()==0)starting_target=-10;shorts_allowed=false;}

if (exit_on_reverse&&signal== "short"&&OrderType() == OP_BUY ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );if (OrdersTotal()==0)starting_target=-10;longs_allowed=false;}
           
if (exit_on_reverse&&signal== "long"&&OrderType() == OP_SELL ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );if (OrdersTotal()==0)starting_target=-10;shorts_allowed=false;}
}
}
return;
}

void run_statistics_longs()
{
GBPUSDm_now= iClose(long_basket1, 0, 0);
EURGBPm_now= iClose(long_basket2, 0, 0);
GBPJPYm_now= iClose(long_basket3, 0, 0);
USDCHFm_now= iClose(long_basket4, 0, 0);
NZDUSDm_now= iClose(long_basket5, 0, 0);
AUDJPYm_now= iClose(long_basket6, 0, 0);
EURJPYm_now= iClose(long_basket7, 0, 0);
int    spread1=MarketInfo(long_basket1,MODE_SPREAD);
int    spread2=MarketInfo(long_basket2,MODE_SPREAD);
int    spread3=MarketInfo(long_basket3,MODE_SPREAD);
int    spread4=MarketInfo(long_basket4,MODE_SPREAD);
int    spread5=MarketInfo(long_basket5,MODE_SPREAD);
int    spread6=MarketInfo(long_basket6,MODE_SPREAD);
int    spread7=MarketInfo(long_basket7,MODE_SPREAD);
GBPUSDm_pips = (GBPUSDm_now-GBPUSDm)/MarketInfo(long_basket1,MODE_POINT)-spread1;
GBPUSDm_pips = GBPUSDm_pips*MarketInfo(long_basket1,MODE_TICKVALUE);

EURGBPm_pips = (EURGBPm_now-EURGBPm)/MarketInfo(long_basket2,MODE_POINT)-spread2;
EURGBPm_pips = EURGBPm_pips*MarketInfo(long_basket2,MODE_TICKVALUE);

GBPJPYm_pips = (GBPJPYm_now-GBPJPYm)/MarketInfo(long_basket3,MODE_POINT)-spread3;
GBPJPYm_pips = GBPJPYm_pips*MarketInfo(long_basket3,MODE_TICKVALUE);

USDCHFm_pips = (USDCHFm_now-USDCHFm)/MarketInfo(long_basket4,MODE_POINT)-spread4;
USDCHFm_pips = USDCHFm_pips*MarketInfo(long_basket4,MODE_TICKVALUE);

NZDUSDm_pips = (NZDUSDm_now-NZDUSDm)/MarketInfo(long_basket5,MODE_POINT)-spread5;
NZDUSDm_pips = NZDUSDm_pips*MarketInfo(long_basket5,MODE_TICKVALUE);

AUDJPYm_pips = (AUDJPYm_now-AUDJPYm)/MarketInfo(long_basket6,MODE_POINT)-spread6;
AUDJPYm_pips = AUDJPYm_pips*MarketInfo(long_basket6,MODE_TICKVALUE);

EURJPYm_pips = (EURJPYm_now-EURJPYm)/MarketInfo(long_basket7,MODE_POINT)-spread7;
EURJPYm_pips = EURJPYm_pips*MarketInfo(long_basket7,MODE_TICKVALUE);

long_pips = GBPUSDm_pips + EURGBPm_pips + GBPJPYm_pips + USDCHFm_pips + NZDUSDm_pips + AUDJPYm_pips + EURJPYm_pips;
if (long_pips>highest_long_pips) highest_long_pips=long_pips;
return;
}

void run_statistics_shorts()
{
EURUSDm_now= iClose(short_basket1, 0, 0);
USDJPYm_now= iClose(short_basket2, 0, 0);
AUDUSDm_now= iClose(short_basket3, 0, 0);
NZDJPYm_now= iClose(short_basket4, 0, 0);
GBPCHFm_now= iClose(short_basket5, 0, 0);
CHFJPYm_now= iClose(short_basket6, 0, 0);
EURCHFm_now= iClose(short_basket7, 0, 0);
int    spread8=MarketInfo(short_basket1,MODE_SPREAD);
int    spread9=MarketInfo(short_basket2,MODE_SPREAD);
int    spread10=MarketInfo(short_basket3,MODE_SPREAD);
int    spread11=MarketInfo(short_basket4,MODE_SPREAD);
int    spread12=MarketInfo(short_basket5,MODE_SPREAD);
int    spread13=MarketInfo(short_basket6,MODE_SPREAD);
int    spread14=MarketInfo(short_basket7,MODE_SPREAD);
EURUSDm_pips = (EURUSDm-EURUSDm_now)/MarketInfo(short_basket1,MODE_POINT)-spread8;
EURUSDm_pips = EURUSDm_pips*MarketInfo(short_basket1,MODE_TICKVALUE);

USDJPYm_pips = (USDJPYm-USDJPYm_now)/MarketInfo(short_basket2,MODE_POINT)-spread9;
USDJPYm_pips = USDJPYm_pips*MarketInfo(short_basket2,MODE_TICKVALUE);

AUDUSDm_pips = (AUDUSDm-AUDUSDm_now)/MarketInfo(short_basket3,MODE_POINT)-spread10;
AUDUSDm_pips = AUDUSDm_pips*MarketInfo(short_basket3,MODE_TICKVALUE);

NZDJPYm_pips = (NZDJPYm-NZDJPYm_now)/MarketInfo(short_basket4,MODE_POINT)-spread11;
NZDJPYm_pips = NZDJPYm_pips*MarketInfo(short_basket4,MODE_TICKVALUE);

GBPCHFm_pips = (GBPCHFm-GBPCHFm_now)/MarketInfo(short_basket5,MODE_POINT)-spread12;
GBPCHFm_pips = GBPCHFm_pips*MarketInfo(short_basket5,MODE_TICKVALUE);

CHFJPYm_pips = (CHFJPYm-CHFJPYm_now)/MarketInfo(short_basket6,MODE_POINT)-spread13;
CHFJPYm_pips = CHFJPYm_pips*MarketInfo(short_basket6,MODE_TICKVALUE);

EURCHFm_pips = (EURCHFm-EURCHFm_now)/MarketInfo(short_basket7,MODE_POINT)-spread14;
EURCHFm_pips = EURCHFm_pips*MarketInfo(short_basket7,MODE_TICKVALUE);




short_pips = EURUSDm_pips + USDJPYm_pips + AUDUSDm_pips + NZDJPYm_pips + GBPCHFm_pips + CHFJPYm_pips + EURCHFm_pips;
if (short_pips>highest_short_pips) highest_short_pips=short_pips;
return;
}



void draw_objects()
{
int companion =WindowFind("trendchaser_companion");
if (companion == -1)companion=0;
   blue=0;red=0;                                                                                  
   string PairsDisplay[14];   
   color  PairsColor[14];              
   double PLArray[14];
   PLArray[0]=GBPUSDm_pips;PLArray[1]=EURGBPm_pips;PLArray[2]=GBPCHFm_pips;PLArray[3]=CHFJPYm_pips;PLArray[4]=AUDJPYm_pips;PLArray[5]=EURJPYm_pips;
   PLArray[6]=USDCHFm_pips;PLArray[7]=NZDJPYm_pips;PLArray[8]=AUDUSDm_pips;PLArray[9]=USDJPYm_pips;PLArray[10]=EURUSDm_pips;
   PLArray[11]=EURCHFm_pips;PLArray[12]=GBPJPYm_pips;PLArray[13]=NZDUSDm_pips;
   ArraySort(PLArray,WHOLE_ARRAY,0,MODE_DESCEND);
   
   for(int i=0;i<=13;i++)
    { 
      if(GBPUSDm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket1+"";
         PairsColor[i] = Green; 
         if (GBPUSDm_pips>0)     blue++;
        
       }
      if(EURGBPm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket2+"";
         PairsColor[i] = Green;  
         if (EURGBPm_pips>0)     blue++;
         
       }
      if(AUDJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket6+""; 
         PairsColor[i] = Green; 
         if (AUDJPYm_pips>0)     blue++;
         
       }
      if(EURJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket7+""; 
         PairsColor[i] = Green; 
         if (EURJPYm_pips>0)     blue++;
         
       }
      if(USDCHFm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket4+""; 
         PairsColor[i] = Green; 
         if (USDCHFm_pips>0)     blue++;
         
       }
      if(GBPJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket3+"";
         PairsColor[i] = Green; 
         if (GBPJPYm_pips>0)     blue++;
        
       }
      if(NZDUSDm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+long_basket5+""; 
         PairsColor[i] = Green; 
         if (NZDUSDm_pips>0)     blue++;
        
       }
      if(NZDJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket4+"";
         PairsColor[i] = Red; 
         if (NZDJPYm_pips>0)     red++;
         
       }
      if(AUDUSDm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket3+""; 
         PairsColor[i] = Red;
         if (AUDUSDm_pips>0)     red++;
        
       }
      if(USDJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket2+""; 
         PairsColor[i] = Red;
         if (USDJPYm_pips>0)     red++;
         
       }
      if(EURUSDm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket1+""; 
         PairsColor[i] = Red; 
         if (EURUSDm_pips>0)     red++;
         
       }
      if(EURCHFm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket7+""; 
         PairsColor[i] = Red; 
         if (EURCHFm_pips>0)     red++;
         
       }
      if(GBPCHFm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket5+"";
         PairsColor[i] = Red;  
         if (GBPCHFm_pips>0)     red++;
         
       }
      if(CHFJPYm_pips==PLArray[i]) 
       {
         PairsDisplay[i] = ""+short_basket6+""; 
         PairsColor[i] = Red; 
         if (CHFJPYm_pips>0)     red++;
         
       }
      Print(PairsDisplay[i],"...",i,"..",PairsColor[i]);
    }

if (ObjectFind("1") == -1 ){
ObjectCreate("1", OBJ_LABEL, companion, 0, 0);
ObjectSet("1", OBJPROP_COLOR, Red);
ObjectSet("1", OBJPROP_XDISTANCE, 10);
ObjectSet("1", OBJPROP_YDISTANCE, 40);}
if (PLArray[0]>0){ObjectSetText("1",PairsDisplay[0]+" =  "+DoubleToStr(PLArray[0],0), 10,"Times New Roman",PairsColor[0]);}
if (PLArray[0]<0){ObjectSetText("1",PairsDisplay[0]+" =  "+DoubleToStr(PLArray[0],0), 10,"Times New Roman",PairsColor[0]);}

if (ObjectFind("2") == -1 ){
ObjectCreate("2", OBJ_LABEL, companion, 0, 0);
ObjectSet("2", OBJPROP_COLOR, Red);
ObjectSet("2", OBJPROP_XDISTANCE, 10);
ObjectSet("2", OBJPROP_YDISTANCE, 60);}
if (PLArray[1]>0){ObjectSetText("2",PairsDisplay[1]+" =  "+DoubleToStr(PLArray[1],0), 10,"Times New Roman",PairsColor[1]);}
if (PLArray[1]<0){ObjectSetText("2",PairsDisplay[1]+" =  "+DoubleToStr(PLArray[1],0), 10,"Times New Roman",PairsColor[1]);}

if (ObjectFind("3") == -1 ){
ObjectCreate("3", OBJ_LABEL, companion, 0, 0);
ObjectSet("3", OBJPROP_COLOR, Red);
ObjectSet("3", OBJPROP_XDISTANCE, 10);
ObjectSet("3", OBJPROP_YDISTANCE, 80);}
if (PLArray[2]>0){ObjectSetText("3",PairsDisplay[2]+" =  "+DoubleToStr(PLArray[2],0), 10,"Times New Roman",PairsColor[2]);}
if (PLArray[2]<0){ObjectSetText("3",PairsDisplay[2]+" =  "+DoubleToStr(PLArray[2],0), 10,"Times New Roman",PairsColor[2]);}

if (ObjectFind("4") == -1 ){
ObjectCreate("4", OBJ_LABEL, companion, 0, 0);
ObjectSet("4", OBJPROP_COLOR, Red);
ObjectSet("4", OBJPROP_XDISTANCE, 10);
ObjectSet("4", OBJPROP_YDISTANCE, 100);}
if (PLArray[3]>0){ObjectSetText("4",PairsDisplay[3]+" =  "+DoubleToStr(PLArray[3],0), 10,"Times New Roman",PairsColor[3]);}
if (PLArray[3]<0){ObjectSetText("4",PairsDisplay[3]+" =  "+DoubleToStr(PLArray[3],0), 10,"Times New Roman",PairsColor[3]);}

if (ObjectFind("5") == -1 ){
ObjectCreate("5", OBJ_LABEL, companion, 0, 0);
ObjectSet("5", OBJPROP_COLOR, Red);
ObjectSet("5", OBJPROP_XDISTANCE, 10);
ObjectSet("5", OBJPROP_YDISTANCE, 120);}
if (PLArray[4]>0){ObjectSetText("5",PairsDisplay[4]+" =  "+DoubleToStr(PLArray[4],0), 10,"Times New Roman",PairsColor[4]);}
if (PLArray[4]<0){ObjectSetText("5",PairsDisplay[4]+" =  "+DoubleToStr(PLArray[4],0), 10,"Times New Roman",PairsColor[4]);}

if (ObjectFind("6") == -1 ){
ObjectCreate("6", OBJ_LABEL, companion, 0, 0);
ObjectSet("6", OBJPROP_COLOR, Red);
ObjectSet("6", OBJPROP_XDISTANCE, 10);
ObjectSet("6", OBJPROP_YDISTANCE, 140);}
if (PLArray[5]>0){ObjectSetText("6",PairsDisplay[5]+" =  "+DoubleToStr(PLArray[5],0), 10,"Times New Roman",PairsColor[5]);}
if (PLArray[5]<0){ObjectSetText("6",PairsDisplay[5]+" =  "+DoubleToStr(PLArray[5],0), 10,"Times New Roman",PairsColor[5]);}

if (ObjectFind("7") == -1 ){
ObjectCreate("7", OBJ_LABEL, companion, 0, 0);
ObjectSet("7", OBJPROP_COLOR, Red);
ObjectSet("7", OBJPROP_XDISTANCE, 10);
ObjectSet("7", OBJPROP_YDISTANCE, 160);}
if (PLArray[6]>0){ObjectSetText("7",PairsDisplay[6]+" =  "+DoubleToStr(PLArray[6],0), 10,"Times New Roman",PairsColor[6]);}
if (PLArray[6]<0){ObjectSetText("7",PairsDisplay[6]+" =  "+DoubleToStr(PLArray[6],0), 10,"Times New Roman",PairsColor[6]);}

if (ObjectFind("8") == -1 ){
ObjectCreate("8", OBJ_LABEL, companion, 0, 0);
ObjectSet("8", OBJPROP_COLOR, Red);
ObjectSet("8", OBJPROP_XDISTANCE, 10);
ObjectSet("8", OBJPROP_YDISTANCE, 200);}
if (PLArray[7]>0){ObjectSetText("8",PairsDisplay[7]+" =  "+DoubleToStr(PLArray[7],0), 10,"Times New Roman",PairsColor[7]);}
if (PLArray[7]<0){ObjectSetText("8",PairsDisplay[7]+" =  "+DoubleToStr(PLArray[7],0), 10,"Times New Roman",PairsColor[7]);}

if (ObjectFind("9") == -1 ){
ObjectCreate("9", OBJ_LABEL, companion, 0, 0);
ObjectSet("9", OBJPROP_COLOR, Red);
ObjectSet("9", OBJPROP_XDISTANCE, 10);
ObjectSet("9", OBJPROP_YDISTANCE, 220);}
if (PLArray[8]>0){ObjectSetText("9",PairsDisplay[8]+" =  "+DoubleToStr(PLArray[8],0), 10,"Times New Roman",PairsColor[8]);}
if (PLArray[8]<0){ObjectSetText("9",PairsDisplay[8]+" =  "+DoubleToStr(PLArray[8],0), 10,"Times New Roman",PairsColor[8]);}

if (ObjectFind("10") == -1 ){
ObjectCreate("10", OBJ_LABEL, companion, 0, 0);
ObjectSet("10", OBJPROP_COLOR, Red);
ObjectSet("10", OBJPROP_XDISTANCE, 10);
ObjectSet("10", OBJPROP_YDISTANCE, 240);}
if (PLArray[9]>0){ObjectSetText("10",PairsDisplay[9]+" =  "+DoubleToStr(PLArray[9],0), 10,"Times New Roman",PairsColor[9]);}
if (PLArray[9]<0){ObjectSetText("10",PairsDisplay[9]+" =  "+DoubleToStr(PLArray[9],0), 10,"Times New Roman",PairsColor[9]);}

if (ObjectFind("11") == -1 ){
ObjectCreate("11", OBJ_LABEL, companion, 0, 0);
ObjectSet("11", OBJPROP_COLOR, Red);
ObjectSet("11", OBJPROP_XDISTANCE, 10);
ObjectSet("11", OBJPROP_YDISTANCE, 260);}
if (PLArray[10]>0){ObjectSetText("11",PairsDisplay[10]+" =  "+DoubleToStr(PLArray[10],0), 10,"Times New Roman",PairsColor[10]);}
if (PLArray[10]<0){ObjectSetText("11",PairsDisplay[10]+" =  "+DoubleToStr(PLArray[10],0), 10,"Times New Roman",PairsColor[10]);}

if (ObjectFind("12") == -1 ){
ObjectCreate("12", OBJ_LABEL, companion, 0, 0);
ObjectSet("12", OBJPROP_COLOR, Red);
ObjectSet("12", OBJPROP_XDISTANCE, 10);
ObjectSet("12", OBJPROP_YDISTANCE, 280);}
if (PLArray[11]>0){ObjectSetText("12",PairsDisplay[11]+" =  "+DoubleToStr(PLArray[11],0), 10,"Times New Roman",PairsColor[11]);}
if (PLArray[11]<0){ObjectSetText("12",PairsDisplay[11]+" =  "+DoubleToStr(PLArray[11],0), 10,"Times New Roman",PairsColor[11]);}

if (ObjectFind("13") == -1 ){
ObjectCreate("13", OBJ_LABEL, companion, 0, 0);
ObjectSet("13", OBJPROP_COLOR, Red);
ObjectSet("13", OBJPROP_XDISTANCE, 10);
ObjectSet("13", OBJPROP_YDISTANCE, 300);}
if (PLArray[12]>0){ObjectSetText("13",PairsDisplay[12]+" =  "+DoubleToStr(PLArray[12],0), 10,"Times New Roman",PairsColor[12]);}
if (PLArray[12]<0){ObjectSetText("13",PairsDisplay[12]+" =  "+DoubleToStr(PLArray[12],0), 10,"Times New Roman",PairsColor[12]);}

if (ObjectFind("14") == -1 ){
ObjectCreate("14", OBJ_LABEL, companion, 0, 0);
ObjectSet("14", OBJPROP_COLOR, Red);
ObjectSet("14", OBJPROP_XDISTANCE, 10);
ObjectSet("14", OBJPROP_YDISTANCE, 320);}
if (PLArray[13]>0){ObjectSetText("14",PairsDisplay[13]+" =  "+DoubleToStr(PLArray[13],0), 10,"Times New Roman",PairsColor[13]);}
if (PLArray[13]<0){ObjectSetText("14",PairsDisplay[13]+" =  "+DoubleToStr(PLArray[13],0), 10,"Times New Roman",PairsColor[13]);}

if (ObjectFind("sig") == -1 ){
ObjectCreate("sig", OBJ_LABEL, companion, 0, 0);
ObjectSet("sig", OBJPROP_COLOR, Red);
ObjectSet("sig", OBJPROP_XDISTANCE, 125);
ObjectSet("sig", OBJPROP_YDISTANCE, 450);}
ObjectSetText("sig","Signal= Ranging", 16,"Times New Roman",Gray);
if (signal == "long"){ObjectSetText("sig","Signal= Buy", 16,"Times New Roman",Blue);shorts_allowed=true;
if (alert&&long_alert)PlaySound("alert.wav");long_alert=false;short_alert=true;}

if (counter_trade&&signal == "reversing to longs"){ObjectSetText("sig","Signal= Counter Buy", 16,"Times New Roman",Blue);shorts_allowed=true;
if (counter_trade&&alert&&long_alert)PlaySound("alert.wav");long_alert=false;short_alert=true;}


if (signal == "short"){ObjectSetText("sig","Signal= Sell", 16,"Times New Roman",Red);longs_allowed=true;
if (alert&&short_alert)PlaySound("alert.wav");short_alert=false;long_alert=true;}

if (counter_trade&&signal == "reversing to shorts"){ObjectSetText("sig","Signal= Counter Sell", 16,"Times New Roman",Red);longs_allowed=true;
if (counter_trade&&alert&&short_alert)PlaySound("alert.wav");short_alert=false;long_alert=true;}

if (signal == "none"){ObjectSetText("sig","Signal= Ranging", 16,"Times New Roman",Gray);longs_allowed=true;shorts_allowed=true;
short_alert=true;long_alert=true;}


/*
double total = short_pips+long_pips;
if (ObjectFind("tot") == -1 ){
ObjectCreate("tot", OBJ_LABEL, companion, 0, 0);
ObjectSet("tot", OBJPROP_COLOR, Red);
ObjectSet("tot", OBJPROP_XDISTANCE, 10);
ObjectSet("tot", OBJPROP_YDISTANCE, 360);}
ObjectSetText("tot","Total= "+total+"", 16,"Times New Roman",Yellow);

*/
string pcnt2 = DoubleToStr(pcnt,2);
string target2 = DoubleToStr(starting_target,2);
if (ObjectFind("pc") == -1 ){
ObjectCreate("pc", OBJ_LABEL, companion, 0, 0);
ObjectSet("pc", OBJPROP_COLOR, Red);
ObjectSet("pc", OBJPROP_XDISTANCE, 220);
ObjectSet("pc", OBJPROP_YDISTANCE, 20);}
ObjectSetText("pc","Profit = "+pcnt2+" %", profit_font_size,"Times New Roman",Yellow);


if (ObjectFind("open_longs") == -1 )
{
ObjectCreate("open_longs", OBJ_LABEL, companion, 0, 0);
ObjectSet("open_longs", OBJPROP_COLOR, Red);
ObjectSet("open_longs", OBJPROP_XDISTANCE, 140);
ObjectSet("open_longs", OBJPROP_YDISTANCE, 150);
ObjectSetText("open_longs","open_longs", 16,"Times New Roman",DeepSkyBlue);}                                                                 
if (ObjectGet("open_longs", OBJPROP_XDISTANCE) != 140)
{
longs_allowed=true;
buy();  
orders(); 
if (buys != 14) {buy();orders(); }  
      if (buys != 14) {buy();orders(); } 
             if (buys != 14) {buy();orders(); } 
                    if (buys != 14) {buy();orders(); }                            
ObjectSet ("open_longs", OBJPROP_XDISTANCE, 140);
ObjectSet ("open_longs", OBJPROP_YDISTANCE, 150);}

if (ObjectFind("open_shorts") == -1 )
{
ObjectCreate("open_shorts", OBJ_LABEL, companion, 0, 0);
ObjectSet("open_shorts", OBJPROP_COLOR, Red);
ObjectSet("open_shorts", OBJPROP_XDISTANCE, 140);
ObjectSet("open_shorts", OBJPROP_YDISTANCE, 180);
ObjectSetText("open_shorts","open_shorts", 16,"Times New Roman",Orange);}                                                                 
if (ObjectGet("open_shorts", OBJPROP_XDISTANCE) != 140)
{
shorts_allowed=true;
sell();
orders(); 
if (sells != 14) {sell(); orders(); }  
    if (sells != 14) {sell(); orders(); } 
        if (sells != 14) {sell(); orders(); } 
            if (sells != 14) {sell(); orders(); }                                        
ObjectSet ("open_shorts", OBJPROP_XDISTANCE, 140);
ObjectSet ("open_shorts", OBJPROP_YDISTANCE, 180);}

if (ObjectFind("close") == -1 )
{
ObjectCreate("close", OBJ_LABEL, companion, 0, 0);
ObjectSet("close", OBJPROP_COLOR, Red);
ObjectSet("close", OBJPROP_XDISTANCE, 290);
ObjectSet("close", OBJPROP_YDISTANCE, 115);
ObjectSetText("close","close all", 16,"Times New Roman",Red);}                                                                 
if (ObjectGet("close", OBJPROP_XDISTANCE) != 290)
{
close();                                                       
ObjectSet ("close", OBJPROP_XDISTANCE, 290);
ObjectSet ("close", OBJPROP_YDISTANCE, 115);}

if (ObjectFind("close2") == -1 )
{
ObjectCreate("close2", OBJ_LABEL, companion, 0, 0);
ObjectSet("close2", OBJPROP_COLOR, Red);
ObjectSet("close2", OBJPROP_XDISTANCE, 400);
ObjectSet("close2", OBJPROP_YDISTANCE, 115);
ObjectSetText("close2","close half", 16,"Times New Roman",Red);}                                                                 
if (ObjectGet("close2", OBJPROP_XDISTANCE) != 400)
{

close_half();                                                       
ObjectSet ("close2", OBJPROP_XDISTANCE, 400);
ObjectSet ("close2", OBJPROP_YDISTANCE, 115);}


if (ObjectFind("closel") == -1 )
{
ObjectCreate("closel", OBJ_LABEL, companion, 0, 0);
ObjectSet("closel", OBJPROP_COLOR, Red);
ObjectSet("closel", OBJPROP_XDISTANCE, 290);
ObjectSet("closel", OBJPROP_YDISTANCE, 150);
ObjectSetText("closel","close longs", 16,"Times New Roman",DeepSkyBlue);}                                                                 
if (ObjectGet("closel", OBJPROP_XDISTANCE) != 290)
{

close_longs();                                                       
ObjectSet ("closel", OBJPROP_XDISTANCE, 290);
ObjectSet ("closel", OBJPROP_YDISTANCE, 150);}

if (ObjectFind("closes") == -1 )
{
ObjectCreate("closes", OBJ_LABEL, companion, 0, 0);
ObjectSet("closes", OBJPROP_COLOR, Red);
ObjectSet("closes", OBJPROP_XDISTANCE, 290);
ObjectSet("closes", OBJPROP_YDISTANCE, 180);
ObjectSetText("closes","close shorts", 16,"Times New Roman",Orange);}                                                                 
if (ObjectGet("closes", OBJPROP_XDISTANCE) != 290)
{

close_shorts();                                                       
ObjectSet ("closel", OBJPROP_XDISTANCE, 290);
ObjectSet ("closel", OBJPROP_YDISTANCE, 180);}

if (ObjectFind("etrail") == -1 )
{
ObjectCreate("etrail", OBJ_LABEL, companion, 0, 0);
ObjectSet("etrail", OBJPROP_COLOR, Red);
ObjectSet("etrail", OBJPROP_XDISTANCE, 430);
ObjectSet("etrail", OBJPROP_YDISTANCE, 40);
ObjectSetText("etrail","equity trail", 16,"Times New Roman",Gray);}   
                                                              
if (equity_trail==false&&ObjectGet("etrail", OBJPROP_XDISTANCE) != 430)
{
equity_trail=true;                                                      
ObjectSet ("etrail", OBJPROP_XDISTANCE, 430);
ObjectSet ("etrail", OBJPROP_YDISTANCE, 40);
}

if (equity_trail&&ObjectGet("etrail", OBJPROP_XDISTANCE) != 430)
{
equity_trail=false;                                                      
ObjectSet ("etrail", OBJPROP_XDISTANCE, 430);
ObjectSet ("etrail", OBJPROP_YDISTANCE, 40);
}
if (equity_trail==false)ObjectSetText("etrail","equity trail", 16,"Times New Roman",Gray);
if (equity_trail)ObjectSetText("etrail","equity trail", 16,"Times New Roman",White);

if (ObjectFind("lock") == -1 )
{
ObjectCreate("lock", OBJ_LABEL, companion, 0, 0);
ObjectSet("lock", OBJPROP_COLOR, Red);
ObjectSet("lock", OBJPROP_XDISTANCE, 530);
ObjectSet("lock", OBJPROP_YDISTANCE, 40);
ObjectSetText("lock","lock profit now", 16,"Times New Roman",Orange);}                                                                 
if (ObjectGet("lock", OBJPROP_XDISTANCE) != 530)
{


//if (pcnt/2>target)target= pcnt/2; 
  if (pcnt-trail>0&&starting_target<pcnt-trail )starting_target=pcnt-trail;                                                   
ObjectSet ("lock", OBJPROP_XDISTANCE, 530);
ObjectSet ("lock", OBJPROP_YDISTANCE, 40);}

string short_pips2=DoubleToStr(short_pips,0);
string long_pips2=DoubleToStr(long_pips,0);
string highest_short_pips2=DoubleToStr(highest_short_pips,0);
string highest_long_pips2=DoubleToStr(highest_long_pips,0);


if (ObjectFind("s_pips") == -1 ){
ObjectCreate("s_pips", OBJ_LABEL, companion, 0, 0);
ObjectSet("s_pips", OBJPROP_COLOR, Red);
ObjectSet("s_pips", OBJPROP_XDISTANCE, 9);
ObjectSet("s_pips", OBJPROP_YDISTANCE, 360);}
ObjectSetText("s_pips","short pips "+short_pips2+"", 16,"Times New Roman",Orange);

if (ObjectFind("l_pips") == -1 ){
ObjectCreate("l_pips", OBJ_LABEL, companion, 0, 0);
ObjectSet("l_pips", OBJPROP_COLOR, Red);
ObjectSet("l_pips", OBJPROP_XDISTANCE, 9);
ObjectSet("l_pips", OBJPROP_YDISTANCE, 390);}
ObjectSetText("l_pips","long pips "+long_pips2+"", 16,"Times New Roman",DeepSkyBlue);


if (ObjectFind("s_pips2") == -1 ){
ObjectCreate("s_pips2", OBJ_LABEL, companion, 0, 0);
ObjectSet("s_pips2", OBJPROP_COLOR, Red);
ObjectSet("s_pips2", OBJPROP_XDISTANCE, 250);
ObjectSet("s_pips2", OBJPROP_YDISTANCE, 360);}
ObjectSetText("s_pips2","highest "+highest_short_pips2+"", 16,"Times New Roman",Orange);

if (ObjectFind("l_pips2") == -1 ){
ObjectCreate("l_pips2", OBJ_LABEL, companion, 0, 0);
ObjectSet("l_pips2", OBJPROP_COLOR, Red);
ObjectSet("l_pips2", OBJPROP_XDISTANCE, 250);
ObjectSet("l_pips2", OBJPROP_YDISTANCE, 390);}
ObjectSetText("l_pips2","highest "+highest_long_pips2+"", 16,"Times New Roman",DeepSkyBlue);



if (ObjectFind("trgt") == -1 ){
ObjectCreate("trgt", OBJ_LABEL, companion, 0, 0);
ObjectSet("trgt", OBJPROP_COLOR, Red);
ObjectSet("trgt", OBJPROP_XDISTANCE, 140);
ObjectSet("trgt", OBJPROP_YDISTANCE, 40);}
ObjectSetText("trgt","equity stop loss = "+target2+" %", 16,"Times New Roman",White);


}

void close()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType() == OP_BUY ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
 orders();}          
if (OrderType() == OP_SELL ) 
{OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
orders();}
if (buys>0||sells>0){close();}

}
}
return;
}

void close_half()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if ( OrderType() == OP_BUY ) {
OrderClose( OrderTicket(), OrderLots()/2, MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
}
           
if ( OrderType() == OP_SELL ) {
OrderClose( OrderTicket(), OrderLots()/2, MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

}orders();
}
}
return;
}

void close_longs()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType() == OP_BUY ) 
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, Red );  
 orders();
}
}
return;
}

void close_shorts()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType() == OP_SELL ) 
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, Red );   
orders();
}
}
return;
}



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


It plays sound alerts