********
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «ikarus_2.0.mq4» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
Ikarus 2.0 — торговый советник для MetaTrader 4, работающий по принципу сеточной торговли. Советник открывает и сопровождает позиции в обе стороны (Buy и Sell), наращивая объём и/или шаг сетки по выбранной прогрессии. В исходнике прямо указано, что это высокорисковая сеточная торговля и использовать её рекомендуется только на демо-счёте.
Настройки программы
| Настройка | Описание |
|---|---|
| magic | Магический номер — Идентификатор (magic number) ордеров советника. |
| grid distance from one position to the next one; is neither a Pip nor a money dimension (grid_size) | Размер сетки — Расстояние сетки от одной позиции до следующей. Не является ни пунктом, ни денежной величиной. |
| use progression as well for grid distance: 0=none | 1:d'alembert | 2:martingale | 3:fibonacci (gs_progression) | Прогрессия шага сетки — Применять прогрессию также к расстоянию сетки: 0 — без прогрессии, 1 — д'Аламбер, 2 — мартингейл, 3 — Фибоначчи. |
| distance for the profit rate; will rise by number of open Lot size; is neither a Pip nor a money dim (take_profit) | Тейк-профит — Расстояние до целевой прибыли; увеличивается с числом открытых лотов. Не является ни пунктом, ни денежной величиной. |
| percentage of profit that will be protected by trailing stop (profit_lock) | Фиксация прибыли — Процент прибыли, который защищается трейлинг-стопом. |
| volume, to start a new cycle (min_lots) | Минимальный лот — Объём, с которого начинается новый цикл. |
| change account state to red, if equity is warning percent less than max equtiy ever reached (equity_warning) | Предупреждение по equity — Доля просадки от максимально достигнутого значения equity, при которой состояние счёта переводится в красный статус. |
| oder volume progression: 0=none | 1:d'alembert | 2:martingale | 3:fibonacci (progression) | Прогрессия объёма — Прогрессия объёма ордеров: 0 — без прогрессии, 1 — д'Аламбер, 2 — мартингейл, 3 — Фибоначчи. |
| for each direction maximum open postitions of buys and sells (max_positions) | Максимум позиций — Максимальное количество одновременно открытых позиций в каждом направлении (Buy и Sell). |
| hedge option, if more than 4 open trades; new starting volume = volume of 3rd last active volume (unbalance_control) | Контроль дисбаланса — Опция хеджирования: если открыто более 4 сделок, новый стартовый объём равен объёму третьей с конца активной сделки. |
| do not trade, if spread is higher than this value (max_spread) | Максимальный спред — Не торговать, если текущий спред выше этого значения. |
| extern option to hide forecast lines (show_forecast) | Показывать прогноз — Внешняя опция для скрытия линий прогноза. |
Поиск по коду файла
#define max_open_positions 100 // maximum number of open positions, was constant = 50 before
#include <stdlib.mqh>
#include <stderror.mqh>
#define versionNo "2.0"
#define versionBMI "BlackMamba Ikarus " + versionNo
#define versionOld "based on Super Money Grid v1.41"
string key="********** ****** ***";
extern int magic=11235;
int user_slippage=2;
extern int grid_size=20; // grid distance from one position to the next one; is neither a Pip nor a money dimension
extern int gs_progression=3; // use progression as well for grid distance: 0=none | 1:d'alembert | 2:martingale | 3:fibonacci
extern int take_profit=20; // distance for the profit rate; will rise by number of open Lot size; is neither a Pip nor a money dimension
extern double profit_lock=0.3; // percentage of profit that will be protected by trailing stop
extern double min_lots=0.01; // volume, to start a new cycle
extern double equity_warning=0.20; // change account state to red, if equity is warning percent less than max equtiy ever reached
extern double account_risk=1.00; // percentage, for stop and close all open positions; trading will also be stopped
extern int progression=3; // oder volume progression: 0=none | 1:d'alembert | 2:martingale | 3:fibonacci
extern int max_positions=6; // for each direction maximum open postitions of buys and sells
extern int unbalance_control=0; // hedge option, if more than 4 open trades; new starting volume = volume of 3rd last active volume
extern int max_spread=100; // do not trade, if spread is higher than this value
extern int show_forecast=1; // extern option to hide forecast lines
int buy_tickets[max_open_positions];
int sell_tickets[max_open_positions];
double buy_lots[max_open_positions];
double sell_lots[max_open_positions];
double buy_profit[max_open_positions];
double sell_profit[max_open_positions];
double buy_price[max_open_positions];
double sell_price[max_open_positions];
int buys=0;
int sells=0;
double line_buy=0,line_sell=0,line_buy_tmp=0,line_sell_tmp=0,line_buy_next=0,line_sell_next=0,line_buy_ts=0,line_sell_ts=0,line_margincall=0;
double total_buy_profit=0,total_sell_profit=0,total_buy_swap=0,total_sell_swap=0;
double buy_max_profit=0,buy_close_profit=0;
double sell_max_profit=0,sell_close_profit=0;
double total_buy_lots=0,total_sell_lots=0;
double relativeVolume=0;
int colInPlus=clrGreen;
int colInMinus=clrRed;
int colNeutral=clrGray;
int colFontLight=clrWhite;
int colFontDark=clrGray;
int colCodeGreen=clrGreen;
int colCodeYellow=clrGold;
int colCodeRed=clrRed;
int colPauseButtonPassive=clrBlue;
int panelCol=colNeutral; // fore color of neutral panel text
int instrumentCol=colNeutral; // panel color that changes depending on its value
int slippage=0; // is fix; depending on chart: 2 or 20
int retry_attempts= 10;
double sleep_time = 4.0; // in seconds
double sleep_maximum=25.0; // in seconds
string OrderReliable_Fname="OrderReliable fname unset";
static int _OR_err=0;
string OrderReliableVersion="V1_1_1";
enum ACCOUNT_STATE{as_green,as_yellow,as_red};
int accountState=as_green;
double max_equity=0; // maximum of equity ever reached, saved in global vars
int stopNextCycle=0; // flag, if trading will be terminated after next successful cycle, trades normally until cyle is closed
int restAndRealize=0; // flag, if trading will be terminated after next successful cycle, does not open new positions
int stopAll=0; // flag, if stopAll must close all and stop trading or continue with trading
int showComment=1; // flag for comment at left side
bool isFirstStartLoop=true; // flag, to do some things only one time after program start
int btnWidth = 70; // width of smallest buttons
int btnHeight = 30; // height of all buttons
int btnGap= 10; // gap, between buttons
int btnLeftAxis = 200; // distance of button from left screen border
int btnTopAxis = 17; // distance of button from top screen border
int btnNextLeft=btnWidth+btnGap; // distance to next button
int btnNextTop=btnHeight+btnGap; // distance to next button
string debugCommentDyn="\n"; // will be added to regular Comment txt and updated each program loop
string debugCommentStat=""; // will be added only - no updates
string debugCommentCloseBuys=""; // show condition, when cycle will be closed
string debugCommentCloseSells="";
string codeRedMsg=""; // tell user, why account state is yellow or red
string codeYellowMsg="";
double ter_IkarusChannel=0; // line_buy - line_sell
string globalVarsID=Symbol()+"_"+magic+"_"; //ID to specify the global vars from other charts
double ter_priceBuy=0;
double ter_priceSell=0;
double ter_point=0;
int ter_digits=0;
double ter_tick_value=0;
double ter_tick_size =0;
double ter_spread=0;
datetime ter_timeNow=0; // date and time while actual loop
double ter_ticksPerGrid=0; // ticks of 1 min_lot per 1 grid size
double ter_chartMultiplier=1; // if digits = 3 or 5: chart multiplier = 10
string ter_currencySymbol="$"; // ‿ if account is in Euro, $ for all other
double ter_MODE_MARGINHEDGED=MarketInfo(Symbol(),MODE_MARGINHEDGED);
double ter_MODE_MARGININIT=MarketInfo(Symbol(),MODE_MARGININIT);
double ter_MODE_MARGINMAINTENANCE=MarketInfo(Symbol(),MODE_MARGINMAINTENANCE);
double ter_MODE_MARGINREQUIRED=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
int start()
{
// код доступен только после оплаты
}
void WriteIniData()
{
if(!IsTesting())
{
GlobalVariableSet(globalVarsID+"stopNextCycle",stopNextCycle);
GlobalVariableSet(globalVarsID+"restAndRealize",restAndRealize);
GlobalVariableSet(globalVarsID+"stopAll",stopAll);
GlobalVariableSet(globalVarsID+"showComment",showComment); // #044: Add button to show or hide comment
GlobalVariableSet(globalVarsID+"max_equity",DoubleToString(max_equity,2)); // #037: save max equity at global vars
}
}
void ReadIniData()
{
if(!IsTesting())
{
int count=GlobalVariablesTotal();
if(count>0)
{
if(GlobalVariableCheck(globalVarsID+"stopNextCycle"))
stopNextCycle=DoubleToString(GlobalVariableGet(globalVarsID+"stopNextCycle"),0);
if(GlobalVariableCheck(globalVarsID+"restAndRealize"))
restAndRealize=DoubleToString(GlobalVariableGet(globalVarsID+"restAndRealize"),0);
if(GlobalVariableCheck(globalVarsID+"stopAll"))
stopAll=DoubleToString(GlobalVariableGet(globalVarsID+"stopAll"),0);
if(GlobalVariableCheck(globalVarsID+"showComment"))
showComment=DoubleToString(GlobalVariableGet(globalVarsID+"showComment"),0);
if(GlobalVariableCheck(globalVarsID+"max_equity")) // #037: save max equity at global vars
max_equity=DoubleToString(GlobalVariableGet(globalVarsID+"max_equity"),2);
}
}
}
void InitVars()
{
buys=0;
sells=0;
for(int i=0; i<max_open_positions; i++)
{
buy_tickets[i]=0;
buy_lots[i]=0;
buy_profit[i]= 0;
buy_price[i] = 0;
sell_tickets[i]=0;
sell_lots[i]=0;
sell_profit[i]= 0;
sell_price[i] = 0;
}
if(max_positions==0) // if not used, set it to maximum => no restriction
max_positions=max_open_positions;
if(equity_warning==0)
equity_warning=1.0;
if(account_risk==0)
account_risk=1.0;
}
void UpdateVars()
{
int aux_buys=0,aux_sells=0;
double aux_total_buy_profit=0,aux_total_sell_profit=0;
double aux_total_buy_swap=0,aux_total_sell_swap=0;
double aux_total_buy_lots=0,aux_total_sell_lots=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY)
{
buy_tickets[aux_buys]=OrderTicket();
buy_lots[aux_buys]=OrderLots();
buy_profit[aux_buys]= OrderProfit()+OrderCommission()+OrderSwap();
buy_price[aux_buys] = OrderOpenPrice();
aux_total_buy_profit= aux_total_buy_profit+buy_profit[aux_buys];
aux_total_buy_lots=aux_total_buy_lots+buy_lots[aux_buys];
aux_total_buy_swap+=OrderSwap();
aux_buys++;
}
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL)
{
sell_tickets[aux_sells]=OrderTicket();
sell_lots[aux_sells]=OrderLots();
sell_profit[aux_sells]= OrderProfit()+OrderCommission()+OrderSwap();
sell_price[aux_sells] = OrderOpenPrice();
aux_total_sell_profit = aux_total_sell_profit + sell_profit[aux_sells];
aux_total_sell_lots=aux_total_sell_lots+sell_lots[aux_sells];
aux_total_sell_swap+=OrderSwap();
aux_sells++;
}
}
}
buys=aux_buys;
sells=aux_sells;
total_buy_profit=aux_total_buy_profit;
total_sell_profit=aux_total_sell_profit;
total_buy_lots=aux_total_buy_lots;
total_sell_lots=aux_total_sell_lots;
total_buy_swap=aux_total_buy_swap;
total_sell_swap=aux_total_sell_swap;
relativeVolume=MathAbs(total_buy_lots-total_sell_lots);
}
void SortByLots()
{
int aux_tickets;
double aux_lots,aux_profit,aux_price;
for(int i=0; i<buys-1; i++)
{
for(int j=i+1; j<buys; j++)
{
if(buy_lots[i]>0 && buy_lots[j]>0)
{
if(buy_lots[j]<buy_lots[i])
{
aux_lots=buy_lots[i];
buy_lots[i]=buy_lots[j];
buy_lots[j]=aux_lots;
aux_tickets=buy_tickets[i];
buy_tickets[i]=buy_tickets[j];
buy_tickets[j]=aux_tickets;
aux_profit=buy_profit[i];
buy_profit[i]=buy_profit[j];
buy_profit[j]=aux_profit;
aux_price=buy_price[i];
buy_price[i]=buy_price[j];
buy_price[j]=aux_price;
}
}
}
}
for(i=0; i<sells-1; i++)
{
for(j=i+1; j<sells; j++)
{
if(sell_lots[i]>0 && sell_lots[j]>0)
{
if(sell_lots[j]<sell_lots[i])
{
aux_lots=sell_lots[i];
sell_lots[i]=sell_lots[j];
sell_lots[j]=aux_lots;
aux_tickets=sell_tickets[i];
sell_tickets[i]=sell_tickets[j];
sell_tickets[j]=aux_tickets;
aux_profit=sell_profit[i];
sell_profit[i]=sell_profit[j];
sell_profit[j]=aux_profit;
aux_price=sell_price[i];
sell_price[i]=sell_price[j];
sell_price[j]=aux_price;
}
}
}
}
}
void ShowLines()
{
double aux_tp_buy=0,aux_tp_sell=0; // CalculateTP(next positions) = take_profit * pipvalue
double buy_tar=0,sell_tar=0, // local results
diff_tar=0;
double buy_a=0, sell_a=0; // sum: # of total opened min_lots
double buy_b=0, sell_b=0; // sum: price payed for all positions
double buy_pip=0,sell_pip=0; // terminal value: tick_value / min_lots
double buy_v[max_open_positions], // array: # of min_lots of this index; if progression = 0, it is always 1; if prog. = 2 then: 1, 2, 4, 8, ...
sell_v[max_open_positions];
double swapDiff=0; // swap accumulated until actual date
int i;
double myVal=1,offset=0,spreadPart=0,gridSizePart=0;
line_buy=0;line_buy_tmp=0;line_buy_next=0;line_buy_ts=0;
line_sell=0;line_sell_tmp=0;line_sell_next=0;line_sell_ts=0;line_margincall=0;
if(buys<=1) aux_tp_buy=CalculateTP(buy_lots[buys-1]);
else if(progression==0) aux_tp_buy = CalculateTP(buy_lots[0]);
else if(progression==1) aux_tp_buy = buys*CalculateTP(buy_lots[0]);
else if(progression==2) aux_tp_buy = CalculateTP(buy_lots[buys-1]);
else if(progression==3) aux_tp_buy = CalculateTP(buy_lots[buys-1]);
if(sells<=1) aux_tp_sell=CalculateTP(sell_lots[sells-1]);
else if(progression==0) aux_tp_sell = CalculateTP(sell_lots[0]);
else if(progression==1) aux_tp_sell = sells*CalculateTP(sell_lots[0]);
else if(progression==2) aux_tp_sell = CalculateTP(sell_lots[sells-1]);
else if(progression==3) aux_tp_sell = CalculateTP(sell_lots[sells-1]);
double tp_buy=aux_tp_buy;
double tp_sell=aux_tp_sell;
if(buys>=1)
{
buy_pip=CalculatePipValue(buy_lots[0]);
for(i=0;i<max_open_positions;i++) buy_v[i]=0;
for(i=0;i<buys;i++)
{
buy_v[i]=MathRound(buy_lots[i]/buy_lots[0]);
}
for(i=0;i<buys;i++)
{
buy_a = buy_a + buy_v[i];
buy_b = buy_b + buy_price[i]*buy_v[i];
}
buy_tar=aux_tp_buy/(buy_pip/ter_point);
buy_tar=buy_tar+buy_b;
buy_tar=buy_tar/buy_a;
swapDiff=MathAbs(CalculateTicksByPrice(total_buy_lots,total_buy_swap));
line_buy=buy_tar+swapDiff;
HorizontalLine(line_buy,"TakeProfit_buy",DodgerBlue,STYLE_SOLID,2);
ter_IkarusChannel=buy_tar/ter_tick_size; // ter_IkarusChannel=line_buy - line_sell
if(buy_close_profit>0)
{
buy_tar = buy_close_profit/(buy_pip/ter_point);
buy_tar = buy_tar + buy_b;
line_buy_ts=buy_tar/buy_a;
HorizontalLine(line_buy_ts,"ProfitLock_buy",DodgerBlue,STYLE_DASH,1);
}
if(show_forecast && line_buy_ts==0)
{
if(gs_progression==0) line_buy_next=buy_price[buys-1]-ter_ticksPerGrid;
else if(gs_progression==1) line_buy_next=buy_price[buys-1]-buys*ter_ticksPerGrid;
else if(gs_progression==2) line_buy_next=buy_price[buys-1]+CalculateTicksByPrice(buy_lots[buys-1],CalculateSL(buy_lots[buys-1],buys));
else if(gs_progression==3) line_buy_next=buy_price[buys-1]+CalculateTicksByPrice(buy_lots[buys-1],CalculateSL(buy_lots[buys-1],buys));
HorizontalLine(line_buy_next,"Next_buy",DodgerBlue,STYLE_DASHDOT,1);
if(accountState!=as_green && total_buy_profit<0)
{
myVal=MathRound(buy_lots[buys-1]/buy_lots[0]);
buy_a+=myVal;
buy_b=(buy_b+ter_priceSell*myVal);
buy_tar=aux_tp_buy/(buy_pip/ter_point);
line_buy_tmp=(buy_tar+buy_b)/buy_a+swapDiff;
if(line_buy_tmp>0)
HorizontalLine(line_buy_tmp,"NewTakeProfit_buy",clrDarkViolet,STYLE_DASHDOTDOT,1);
}
}
}
if(sells>=1)
{
sell_pip=CalculatePipValue(sell_lots[0]);
for(i=0;i<max_open_positions;i++) sell_v[i]=0;
for(i=0;i<sells;i++)
{
sell_v[i]=MathRound(sell_lots[i]/sell_lots[0]);
}
for(i=0;i<sells;i++)
{
sell_a = sell_a + sell_v[i];
sell_b = sell_b + sell_price[i]*sell_v[i];
}
sell_tar = -1*(aux_tp_sell/(sell_pip/ter_point));
sell_tar = sell_tar + sell_b;
sell_tar = sell_tar/sell_a;
swapDiff = MathAbs(CalculateTicksByPrice(total_sell_lots,total_sell_swap));
line_sell=sell_tar-swapDiff;
HorizontalLine(line_sell,"TakeProfit_sell",Tomato,STYLE_SOLID,2);
ter_IkarusChannel-=sell_tar/ter_tick_size; // ter_IkarusChannel=line_buy - line_sell
if(buys>0 && sells>0) // only valid, if both direction have positions
ter_IkarusChannel=MathAbs(ter_IkarusChannel);
else
ter_IkarusChannel=0;
if(sell_close_profit>0)
{
sell_tar = -1*(sell_close_profit/(sell_pip/ter_point));
sell_tar = sell_tar + sell_b;
line_sell_ts=sell_tar/sell_a;
HorizontalLine(line_sell_ts,"ProfitLock_sell",Tomato,STYLE_DASH,1);
}
if(show_forecast && line_sell_ts==0)
{
if(gs_progression==0) line_sell_next=sell_price[sells-1]+ter_ticksPerGrid;
else if(gs_progression==1) line_sell_next=sell_price[sells-1]+sells*ter_ticksPerGrid;
else if(gs_progression==2) line_sell_next=sell_price[sells-1]-CalculateTicksByPrice(sell_lots[sells-1],CalculateSL(sell_lots[sells-1],sells));
else if(gs_progression==3) line_sell_next=sell_price[sells-1]-CalculateTicksByPrice(sell_lots[sells-1],CalculateSL(sell_lots[sells-1],sells));
HorizontalLine(line_sell_next,"Next_sell",Tomato,STYLE_DASHDOT,1);
if(accountState!=as_green && total_sell_profit<0)
{
myVal=MathRound(sell_lots[sells-1]/sell_lots[0]);
sell_a+=myVal;
sell_b=(sell_b+ter_priceBuy*myVal);
sell_tar=-1*(aux_tp_sell/(sell_pip/ter_point));
line_sell_tmp=(sell_b-(aux_tp_sell/(sell_pip/ter_point)))/sell_a-swapDiff;
if(line_sell_tmp>0)
HorizontalLine(line_sell_tmp,"NewTakeProfit_sell",clrDarkViolet,STYLE_DASHDOTDOT,1);
}
}
}
line_margincall=0;
if(show_forecast && (accountState==as_yellow || accountState==as_red))
{
double freeMargin=AccountFreeMargin();
double maxLoss=freeMargin/ter_tick_value*ter_tick_size;
if(total_buy_profit<total_sell_profit) // calculate line_margincall for worse profit
{
if(total_buy_lots>0)
line_margincall=ter_priceBuy-maxLoss/total_buy_lots;
if(line_margincall>0)
HorizontalLine(line_margincall,"MarginCall",clrSilver,STYLE_SOLID,5);
}
else
{
if(total_sell_lots>0)
line_margincall=ter_priceSell+maxLoss/total_sell_lots;
if(maxLoss<ter_priceSell)
HorizontalLine(line_margincall,"MarginCall",clrSilver,STYLE_SOLID,5);
}
}
if(line_buy==0)
ObjectDelete("TakeProfit_buy");
if(line_buy_next==0)
ObjectDelete("Next_buy");
if(line_buy_tmp==0)
ObjectDelete("NewTakeProfit_buy");
if(line_buy_ts==0)
ObjectDelete("ProfitLock_buy");
if(line_sell==0)
ObjectDelete("TakeProfit_sell");
if(line_sell_next==0)
ObjectDelete("Next_sell");
if(line_sell_tmp==0)
ObjectDelete("NewTakeProfit_sell");
if(line_sell_ts==0)
ObjectDelete("ProfitLock_sell");
if(line_margincall==0)
ObjectDelete("MarginCall");
}
void ShowData()
{
string txt;
double aux_tp_buy=0,aux_tp_sell=0;
string info_money_management[4];
string info_activation[2];
info_money_management[0]="min_lots";
info_money_management[1]="D?Alembert";
info_money_management[2]="Martingale";
info_money_management[3]="Fibonacci";
info_activation[0]="Disabled";
info_activation[1]="Enabled";
if(buys<=1) aux_tp_buy=CalculateTP(buy_lots[buys-1]);
else if(progression==0) aux_tp_buy = CalculateTP(buy_lots[0]);
else if(progression==1) aux_tp_buy = buys*CalculateTP(buy_lots[0]);
else if(progression==2) aux_tp_buy = CalculateTP(buy_lots[buys-1]);
else if(progression==3) aux_tp_buy = CalculateTP(buy_lots[buys-1]);
if(sells<=1) aux_tp_sell=CalculateTP(sell_lots[sells-1]);
else if(progression==0) aux_tp_sell = CalculateTP(sell_lots[0]);
else if(progression==1) aux_tp_sell = sells*CalculateTP(sell_lots[0]);
else if(progression==2) aux_tp_sell = CalculateTP(sell_lots[sells-1]);
else if(progression==3) aux_tp_sell = CalculateTP(sell_lots[sells-1]);
string info_gs_progression;
if(gs_progression==0)
info_gs_progression="\nGS progression: Disabled";
else
info_gs_progression="\nGS progression: "+info_money_management[gs_progression];
txt="\n"+versionBMI+
"\n"+versionOld+
"\nServer Time: "+TimeToStr(ter_timeNow,TIME_DATE|TIME_SECONDS)+
"\n"+
"\nBUY ORDERS"+
"\nNumber of orders: "+buys+
"\nTotal lots: "+DoubleToStr(total_buy_lots,2)+
"\nCurrent profit: "+DoubleToStr(total_buy_profit,2)+
"\nProfit goal: "+ter_currencySymbol+DoubleToStr(aux_tp_buy,2)+
"\nMaximum profit reached: "+ter_currencySymbol+DoubleToStr(buy_max_profit,2)+
"\nProfit locked: "+ter_currencySymbol+DoubleToStr(buy_close_profit,2)+
"\n"+
"\nSELL ORDERS"+
"\nNumber of orders: "+sells+
"\nTotal lots: "+DoubleToStr(total_sell_lots,2)+
"\nCurrent profit: "+DoubleToStr(total_sell_profit,2)+
"\nProfit goal: "+ter_currencySymbol+DoubleToStr(aux_tp_sell,2)+
"\nMaximum profit reached: "+ter_currencySymbol+DoubleToStr(sell_max_profit,2)+
"\nProfit locked: "+ter_currencySymbol+DoubleToStr(sell_close_profit,2)+"\n";
if(line_margincall>0)
txt+="\nLine: \"margin call\": "+DoubleToString(line_margincall,3);
if(codeYellowMsg!="")
txt+="\n"+codeYellowMsg;
if(codeRedMsg!="")
txt+="\n"+codeRedMsg;
txt+=
"\n\nMax. Equity: "+DoubleToString(max_equity,2)+" "+ter_currencySymbol+
"\nCurren drawdown: "+DoubleToString((max_equity-AccountEquity()),2)+" "+ter_currencySymbol+" ("+DoubleToString((max_equity-AccountEquity())/max_equity*100,2)+" %)"+
"\n\nSETTINGS: "+
"\nGrid size: "+grid_size+
info_gs_progression+
"\nTake profit: "+take_profit+
"\nProfit locked: "+DoubleToStr(100*profit_lock,2)+"%"+
"\nMinimum lots: "+DoubleToStr(min_lots,2)+
"\nEquity warning: "+DoubleToStr(100*equity_warning,2)+"%"+
"\nAccount risk: "+DoubleToStr(100*account_risk,2)+"%"+
"\nProgression: "+info_money_management[progression]+
"\nMax Positions: "+max_positions+
"\nUnbalance control: "+info_activation[unbalance_control]+
"\nMax Spread: "+max_spread+" pts; actual spread: "+MarketInfo(Symbol(),MODE_SPREAD)+" pts"+
"\nShow Forecast: "+info_activation[show_forecast]+
"\nID for GlobalVariables: "+globalVarsID+"\n";
ObjectSetInteger(0,"btnShowComment",OBJPROP_STATE,0); // switch color back to not selected
if(showComment)
{
if(ObjectFind(0,"btnManualBuy")==-1)
{
DrawButton("btnManualBuy","Buy",btnLeftAxis,btnTopAxis,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnManualSell","Sell",btnLeftAxis+btnNextLeft,btnTopAxis,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnCloseLastBuy","Cl. Last B",btnLeftAxis,btnTopAxis+btnNextTop,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnCloseLastSell","Cl. Last S",btnLeftAxis+btnNextLeft,btnTopAxis+btnNextTop,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnCloseAllBuys","Cl. All Bs",btnLeftAxis,btnTopAxis+2*btnNextTop,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnCloseAllSells","Cl. All Ss",btnLeftAxis+btnNextLeft,btnTopAxis+2*btnNextTop,btnWidth,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnShowComment","Show/Hide Comment",5,btnTopAxis,btnWidth*2,btnHeight,false,colNeutral,colCodeYellow);
DrawButton("btnstopNextCycle","Stop Next Cycle",btnLeftAxis+2*btnNextLeft,btnTopAxis,MathRound(btnWidth*1.5),btnHeight,false,colNeutral,clrBlack);
DrawButton("btnrestAndRealize","Rest & Realize",btnLeftAxis+2*btnNextLeft,btnTopAxis+btnNextTop,btnWidth*1.5,btnHeight,false,colNeutral,clrBlack);
DrawButton("btnStopAll","Stop & Close",btnLeftAxis+2*btnNextLeft,btnTopAxis+2*btnNextTop,btnWidth*1.5,btnHeight,false,colNeutral,clrBlack);
}
ObjectSetInteger(0,"btnManualBuy",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnManualSell",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnCloseLastBuy",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnCloseLastSell",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnCloseAllBuys",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnCloseAllSells",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnstopNextCycle",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnrestAndRealize",OBJPROP_STATE,0); // switch color back to not selected
ObjectSetInteger(0,"btnStopAll",OBJPROP_STATE,0); // switch color back to not selected
if(stopNextCycle)
{
SetButtonText("btnstopNextCycle","Continue");
if(sells+buys==0)
SetButtonColor("btnstopNextCycle",colCodeRed,colFontLight);
else
SetButtonColor("btnstopNextCycle",colCodeYellow,colFontDark);
}
else
{
SetButtonText("btnstopNextCycle","Stop Next Cycle");
SetButtonColor("btnstopNextCycle",colPauseButtonPassive,colFontLight);
}
if(restAndRealize)
{
SetButtonText("btnrestAndRealize","Continue");
if(sells+buys==0)
SetButtonColor("btnrestAndRealize",colCodeRed,colFontLight);
else
SetButtonColor("btnrestAndRealize",colCodeYellow,colFontDark);
}
else
{
SetButtonText("btnrestAndRealize","Rest & Realize");
SetButtonColor("btnrestAndRealize",colPauseButtonPassive,colFontLight);
}
if(stopAll)
{
SetButtonText("btnStopAll","Continue");
SetButtonColor("btnStopAll",colCodeRed,colFontLight);
}
else
{
SetButtonText("btnStopAll","Stop & Close");
SetButtonColor("btnStopAll",colPauseButtonPassive,colFontLight);
}
}
else
{
DeleteButton("btnStopAll");
DeleteButton("btnrestAndRealize");
DeleteButton("btnstopNextCycle");
DeleteButton("btnManualBuy");
DeleteButton("btnManualSell");
DeleteButton("btnCloseLastBuy");
DeleteButton("btnCloseLastSell");
DeleteButton("btnCloseAllBuys");
DeleteButton("btnCloseAllSells");
}
#ifdef DEBUG
debugCommentDyn+=
"Ikarus Channel: "+DoubleToStr(ter_IkarusChannel,0)+
"\n"+
"\nTick Value: "+DoubleToStr(ter_tick_value,ter_digits)+
"\nTick Size: "+DoubleToStr(ter_tick_size,ter_digits)+
"\nPoint: "+DoubleToStr(ter_point,ter_digits)+
"\nDigits: "+ter_digits+
"\n"+
"\nTicks/Grid Size: "+DoubleToStr(ter_ticksPerGrid,ter_digits)+
"\nRelative Volume: "+DoubleToString(relativeVolume,2)+" Lot"+
"\nAct. Price/Tick: "+DoubleToString(CalculatePriceByTickDiff(relativeVolume,ter_tick_size),ter_digits)+ter_currencySymbol+
"\nAct. Ticks/1,- "+ter_currencySymbol+": "+DoubleToString(CalculateTicksByPrice(relativeVolume,1),ter_digits)+
"\n"+
debugCommentCloseBuys+
debugCommentCloseSells+
"";
if(showComment)
Comment("\n\n"+txt+"\n\nDebug info (switch of in code):"+debugCommentStat+debugCommentDyn);
else
Comment("");
#else
if(showComment)
Comment("\n\n"+txt);
else
Comment("");
#endif
if(show_forecast)
{
if(total_buy_profit+total_sell_profit>0)
instrumentCol=colInPlus;
else
instrumentCol=colInMinus;
Write("panel_1_01",ChartSymbol(0),5,22,"Arial",14,instrumentCol);
if(ter_spread>max_spread)
Write("panel_1_02","Spread: "+DoubleToString(ter_spread/10,1),5,42,"Arial",10,colCodeRed);
else
Write("panel_1_02","Spread: "+DoubleToString(ter_spread/10,1),5,42,"Arial",10,panelCol);
Write("panel_1_03",DoubleToString(CalculatePriceByTickDiff(relativeVolume,ter_tick_size*10),2)+" "+ter_currencySymbol+" / Pip",5,58,"Arial",10,panelCol);
Write("panel_1_04","Balance: "+DoubleToString(AccountBalance(),2)+" "+ter_currencySymbol,5,74,"Arial",10,panelCol);
Write("panel_1_05","Equity: "+DoubleToString(AccountEquity(),2)+" "+ter_currencySymbol,5,90,"Arial",10,panelCol);
Write("panel_1_06","Free Margin: "+DoubleToString(AccountFreeMargin(),2)+" "+ter_currencySymbol,5,106,"Arial",10,panelCol);
Write("panel_1_07","P/L Sym. "+DoubleToString(total_buy_profit+total_sell_profit,2)+" "+ter_currencySymbol,5,122,"Arial",14,instrumentCol);
if(total_buy_profit<0)
Write("panel_1_08","P/L Buy: "+DoubleToStr(total_buy_profit,2)+" "+ter_currencySymbol,5,144,"Arial",10,colInMinus);
else
Write("panel_1_08","P/L Buy: "+DoubleToStr(total_buy_profit,2)+" "+ter_currencySymbol,5,144,"Arial",10,colInPlus);
if(total_sell_profit<0)
Write("panel_1_09","P/L sell: "+DoubleToStr(total_sell_profit,2)+" "+ter_currencySymbol,5,160,"Arial",10,colInMinus);
else
Write("panel_1_09","P/L sell: "+DoubleToStr(total_sell_profit,2)+" "+ter_currencySymbol,5,160,"Arial",10,colInPlus);
double accountPL=AccountProfit();
if(accountPL<0)
Write("panel_1_10","P/L Acc. "+DoubleToString(accountPL,2)+" "+ter_currencySymbol,5,176,"Arial",10,colInMinus);
else
Write("panel_1_10","P/L Acc. "+DoubleToString(accountPL,2)+" "+ter_currencySymbol,5,176,"Arial",10,colInPlus);
double pips2go_Buys = MathAbs(line_buy/ter_tick_size-ter_priceSell/ter_tick_size)/10;
double pips2go_Sells = MathAbs(line_sell/ter_tick_size-ter_priceBuy/ter_tick_size)/10;
Write("panel_1_11","Pips2Go B "+DoubleToString(pips2go_Buys,0)+" S "+DoubleToStr(pips2go_Sells,0),5,192,"Arial",10,panelCol);
}
}
void CheckAccountState()
{
accountState=as_green; // init state
codeYellowMsg=""; // #038: give user info, why account state is yellow or red
codeRedMsg="";
double myPercentage=0;
if(buys>=max_positions)
accountState=as_yellow;
if(sells>=max_positions)
accountState=as_yellow;
if(accountState==as_yellow)
codeYellowMsg="Code YELLOW: Max positions reached";
if(CalculateNextMargin()>AccountFreeMargin())
{
accountState=as_red;
codeRedMsg="Code RED: Next M. "+DoubleToString(CalculateNextMargin(),2)+" > Free M. "+DoubleToString(AccountFreeMargin(),2);
}
if((100-(100*equity_warning))/100*max_equity>AccountEquity())
{
accountState=as_red;
if(codeRedMsg=="")
codeRedMsg="Code RED: Equ. "+NormalizeDouble(AccountEquity(),2)+" < "+NormalizeDouble((100*equity_warning),0)+"% of max. equ. "+NormalizeDouble(max_equity,2);
else
codeRedMsg+="\nand\nEqu. "+NormalizeDouble(AccountEquity(),2)+" < "+NormalizeDouble((100*equity_warning),0)+"% of max. equ. "+NormalizeDouble(max_equity,2);
}
switch(accountState)
{
case as_yellow:
SetButtonColor("btnManualBuy",colCodeYellow,colFontDark);
SetButtonColor("btnManualSell",colCodeYellow,colFontDark);
SetButtonColor("btnCloseLastBuy",colCodeYellow,colFontDark);
SetButtonColor("btnCloseLastSell",colCodeYellow,colFontDark);
SetButtonColor("btnCloseAllBuys",colCodeYellow,colFontDark);
SetButtonColor("btnCloseAllSells",colCodeYellow,colFontDark);
SetButtonColor("btnShowComment",colCodeYellow,colFontDark);
break;
case as_red:
SetButtonColor("btnManualBuy",colCodeRed,colFontLight);
SetButtonColor("btnManualSell",colCodeRed,colFontLight);
SetButtonColor("btnCloseLastBuy",colCodeRed,colFontLight);
SetButtonColor("btnCloseLastSell",colCodeRed,colFontLight);
SetButtonColor("btnCloseAllBuys",colCodeRed,colFontLight);
SetButtonColor("btnCloseAllSells",colCodeRed,colFontLight);
SetButtonColor("btnShowComment",colCodeRed,colFontLight);
break;
default:
SetButtonColor("btnManualBuy",colCodeGreen,colCodeGreen);
SetButtonColor("btnManualSell",colCodeGreen,colCodeGreen);
SetButtonColor("btnCloseLastBuy",colCodeGreen,colCodeGreen);
SetButtonColor("btnCloseLastSell",colCodeGreen,colCodeGreen);
SetButtonColor("btnCloseAllBuys",colCodeGreen,colCodeGreen);
SetButtonColor("btnCloseAllSells",colCodeGreen,colCodeGreen);
SetButtonColor("btnShowComment",colCodeGreen,colFontLight);
break;
}
return;
}
double CalculateVolume(int positions)
{
int factor=0;
int i=0;
if(positions==0)
return(min_lots);
switch(gs_progression)
{
case 0:
factor=1;
break;
case 1:
factor=positions;
break;
case 2:
for(i=1,factor=1;i<positions;i++)
factor=factor*2;
break;
case 3:
factor=CalculateFibonacci(positions);
break;
}
return(factor*min_lots);
}
double CalculateNextVolume(int orderType)
{
if(orderType==OP_BUY && buys==0)
return(min_lots);
if(orderType==OP_SELL && sells==0)
return(min_lots);
switch(progression)
{
case 0:
return(min_lots);
break;
case 1:
if(orderType==OP_BUY)
return(buy_lots[buys-1]+buy_lots[0]);
else
return(sell_lots[sells-1]+sell_lots[0]);
break;
case 2:
if(orderType==OP_BUY)
return(2*buy_lots[buys-1]);
else
return(2*sell_lots[sells-1]);
break;
case 3:
if(orderType==OP_BUY)
return(CalculateFibonacci(buys+1)*buy_lots[0]);
else
return(CalculateFibonacci(sells+1)*sell_lots[0]);
break;
}
return(min_lots);
}
double CalculateNextMargin()
{
double leverage=100/AccountLeverage();
if(buys+sells==0)
return(min_lots*leverage*ter_MODE_MARGINREQUIRED);
if(buys>sells)
return(CalculateNextVolume(OP_BUY)*leverage*ter_MODE_MARGINREQUIRED);
else
return(CalculateNextVolume(OP_SELL)*leverage*ter_MODE_MARGINREQUIRED);
}
void Write(string name,string s,int x,int y,string font,int size,color c)
{
if(ObjectFind(name)==-1)
{
ObjectCreate(name,OBJ_LABEL,0,0,0);
ObjectSet(name,OBJPROP_CORNER,1);
}
ObjectSetText(name,s,size,font,c);
ObjectSet(name,OBJPROP_XDISTANCE,x);
ObjectSet(name,OBJPROP_YDISTANCE,y);
}
void HorizontalLine(double value,string name,color c,int style,int thickness)
{
if(ObjectFind(name)==-1)
{
ObjectCreate(name,OBJ_HLINE,0,Time[0],value);
}
ObjectSet(name,OBJPROP_PRICE1,value);
ObjectSet(name,OBJPROP_STYLE,style);
ObjectSet(name,OBJPROP_COLOR,c);
ObjectSet(name,OBJPROP_WIDTH,thickness);
}
double CalculateStartingVolume()
{
double aux;
aux=min_lots;
if(aux>MarketInfo(Symbol(),MODE_MAXLOT))
aux=MarketInfo(Symbol(),MODE_MAXLOT);
if(aux<MarketInfo(Symbol(),MODE_MINLOT))
aux=MarketInfo(Symbol(),MODE_MINLOT);
return(aux);
}
double CalculateTicksByPrice(double volume,double price)
{
if(volume==0)
return(0);
return(price*ter_tick_size/ter_tick_value/volume);
}
double CalculatePriceByTickDiff(double volume,double diff)
{
return(ter_tick_value*volume*diff/ter_tick_size);
}
double CalculatePipValue(double volume)
{
double aux_mm_value=0;
double aux_mm_tick_value=ter_tick_value;
double aux_mm_tick_size=ter_tick_size;
int aux_mm_digits=ter_digits;
double aux_mm_veces_lots;
if(volume!=0)
{
aux_mm_veces_lots=1/volume;
if(aux_mm_digits==5 || aux_mm_digits==3)
{
aux_mm_value=aux_mm_tick_value*10;
}
else if(aux_mm_digits==4 || aux_mm_digits==2)
{
aux_mm_value=aux_mm_tick_value;
}
aux_mm_value=aux_mm_value/aux_mm_veces_lots;
}
return(aux_mm_value);
}
double CalculateTP(double volume)
{
double aux_take_profit;
aux_take_profit=take_profit*CalculatePipValue(volume);
return(aux_take_profit);
}
double CalculateSL(double volume,int positions)
{
double aux_stop_loss;
double myVal=CalculateVolume(positions)/min_lots; // myVal = # of actual progression
aux_stop_loss=-(myVal*grid_size*CalculatePipValue(volume));
return(aux_stop_loss);
}
void Robot()
{
int ticket=-1;
bool closed=FALSE;
if(((100-(100*account_risk))/100)*AccountBalance()>AccountEquity())
{
stopAll=1;
}
if(buys==0)
{
if(!stopNextCycle && !restAndRealize)
{
if(unbalance_control==0)
ticket=OrderSendReliable(Symbol(),OP_BUY,CalculateStartingVolume(),MarketInfo(Symbol(),MODE_ASK),slippage,0,0,key,magic,0,Blue);
else
{
if(sells<4)
ticket=OrderSendReliable(Symbol(),OP_BUY,CalculateStartingVolume(),MarketInfo(Symbol(),MODE_ASK),slippage,0,0,key,magic,0,Blue);
else
ticket=OrderSendReliable(Symbol(),OP_BUY,sell_lots[sells-3],MarketInfo(Symbol(),MODE_ASK),slippage,0,0,key,magic,0,Blue);
}
}
}
if(buys==1)
{
if(!stopNextCycle && !restAndRealize && max_positions>1)
{
if(buy_profit[buys-1]<=CalculateSL(buy_lots[buys-1],1))
{
NewIkarusOrder(OP_BUY,false);
}
}
if(buy_max_profit==0 && total_buy_profit>CalculateTP(buy_lots[0]))
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*buy_max_profit;
}
if(buy_max_profit>0)
{
if(total_buy_profit>buy_max_profit)
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*total_buy_profit;
}
}
if(buy_max_profit>0 && buy_close_profit>0 && buy_max_profit>buy_close_profit && total_buy_profit<buy_close_profit)
{
CloseAllBuys();
}
} // if (buys==1)
if(buys>1)
{
if(buy_profit[buys-1]<=CalculateSL(buy_lots[buys-1],buys))
{
if(buys<max_open_positions && buys<max_positions) // #007: be able to deal with variable number of open positions
{
NewIkarusOrder(OP_BUY,false);
}
}
if(buy_max_profit==0 && progression==0 && total_buy_profit>CalculateTP(buy_lots[0]))
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*buy_max_profit;
}
if(buy_max_profit==0 && progression==1 && total_buy_profit>buys*CalculateTP(buy_lots[0]))
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*buy_max_profit;
}
if(buy_max_profit==0 && progression==2 && total_buy_profit>CalculateTP(buy_lots[buys-1]))
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*buy_max_profit;
}
if(buy_max_profit==0 && progression==3 && total_buy_profit>CalculateTP(buy_lots[buys-1]))
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*buy_max_profit;
}
if(buy_max_profit>0)
{
if(total_buy_profit>buy_max_profit)
{
buy_max_profit=total_buy_profit;
buy_close_profit=profit_lock*total_buy_profit;
}
}
if(buy_max_profit>0 && buy_close_profit>0 && buy_max_profit>buy_close_profit && total_buy_profit<buy_close_profit)
{
Показано первые 50% кода (символов: 61666)
Открыть по тарифу
Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.
Разовая покупка файла
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? После подтверждения оплаты файл сохранится в кабинете на этот email. Если аккаунта ещё нет, мы создадим его и пришлём ссылку для задания пароля. Если аккаунт уже есть, покупка добавится в него. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.