| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975 |
- //+------------------------------------------------------------------+
- //| localHedgingMasterCopierMt5.mq5 |
- //| Copyright 2025, MQL Development |
- //| https://www.mqldevelopment.com/ |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2025, MQL Development"
- #property link "https://www.mqldevelopment.com/"
- #property version "1.00"
- #include <Trade\Trade.mqh>
- CTrade trade;
- #define orderCount 2000
- #define count1 50
- #define testCounter 50
- #define MaxOrders 20000
- #define daysOfTradesToAdd 20
-
- #property description "Control Panels and Dialogs. Demonstration class CLabel"
- #include <Controls\Dialog.mqh>
- #include <Controls\Label.mqh>
- #include <Controls\Button.mqh>
- #include <Controls\RadioButton.mqh>
- #include <Controls\RadioGroup.mqh>
- #include <Controls\CheckBox.mqh>
- #include <Controls\ComboBox.mqh>
- //+------------------------------------------------------------------+
- //| Expert initialization function |
- //+------------------------------------------------------------------+
- struct historyTradesClientSide
- {
- ulong ticket;
- ulong magic;
- historyTradesClientSide()
- {
- ticket = -1;
- magic = 0;
- }
- };
- historyTradesClientSide historyTradeStore[MaxOrders];
-
- struct masterOrder
- {
- datetime opentime;
- string symbol;
- ulong ordertype;
- double price;
- double lots;
- double stoploss;
- double takeprofit;
- ulong ticket;
-
- ulong magic;
- double accountBalance;
- int contractSize;
- string comment;
-
-
- masterOrder()
- {
- ticket=-1;
- price=-1;
- symbol=Symbol();
- ordertype=-1;
- lots=0;
- stoploss=0;
- takeprofit=0;
- }
- };
- masterOrder mod1[orderCount];
-
- struct order
- {
- ulong ticket;
- double price;
- datetime opentime;
- string symbol;
- int ordertype;
- double lots;
- double stoploss;
- double takeprofit;
- double accountBalance;
- int contractSize;
- string comments;
- ulong magicNo;
- order()
- {
- ticket =-1;
- }
- };
-
- struct clientOrder
- {
- ulong ticket;
- double price;
- datetime opentime;
- string symbol;
- int ordertype;
- double lots;
- double stoploss;
- double takeprofit;
- ulong magic;
- string comments;
- double masterLot;
- clientOrder()
- {
- ticket=-1;
- price=-1;
- symbol=Symbol();
- ordertype=-1;
- lots=0;
- masterLot=0;
- stoploss=0;
- takeprofit=0;
- magic=-1;
- comments="";
- }
- };
- clientOrder cod[orderCount];
-
-
- enum operation_mode
- {
- Master, //Master
- Slave, //Slave
- };
- enum lotcalculator
- {
- fix, //Fixed Lot Size
- rsk, //Risk Percentage
- };
-
- sinput string string_0 = "<><><><><><> General SETTINGS <><><><><><>"; //__
- input int magic_no = 333; // Magic no
- input string suffix = ""; // Suffix
- input string prefix = ""; // Prefix
- input bool useMinimumLot = false; // Use Minimum Lot Threshold
- input double takeprofitTrade = 10; // Fixed Take Profit in Pips
- input double stoplossTrade = 10; // Fixed Stop Loss in Pips
- input double inpPips = 0.2; // Pips To Start Copy
- input double minimumLot = 0.01; // Minimum Lot
- input bool useMaximumLot = false; // Use Maximum Lot Threshold
- input double maximumLot = 0.01; // Maximum Lot
-
- input string string_0_3 = "<><><><><><> Lot Management<><><><><><>"; //__
- input double lot_size = 0.1; // Lot Size
- input lotcalculator lot_calculator = fix; // Lot Size Calculator
- input double risk = 0.1; // Risk in Percentage %
-
- // Heart Beat
- sinput string string_1 = "<><><><><><> HeartBeat Setting <><><><><><>"; //__
- input string slaveServer = ""; // Slave Server
- input string slaveId = ""; // Slave Login ID
- input string masterServer = ""; // Master Server
- input string slaveVersion = "4"; // Slave Version
- input string localApiKey = "U2FsdGVkX18vBY4H1uzQiZwuh8B++8VBtCGJ3yGr2XPII0qCodmfuhjssKu5oug1J4e97bkwPtDQLi4py1OODQ=="; // Local API Key
- input string localHB_req_link = "http://localhost/api/mlastConnected"; // Request Link For LastConnected
-
- input string dashboardSettings = "<><><><><><> Dashboard Settings<><><><><><>";
- input int DashHeight = 115; // Enter Height of Dashboard
- input int DashWidth = 490; // Enter Width of Dashboard
- input int FontSize = 10; // Text Font Size
-
- // Global Variables
- int filehandle;
- int gmtDifference = 0;
- bool doReversal = true; // Reverse Trades
- bool auth = false;
- datetime last_check_expiry;
- ENUM_TIMEFRAMES check_expiry_timeframe = PERIOD_H1;
- int orderTotal=0;
-
- bool fileLastEmpty=false;
- bool fileHandlerIssue=false;
- int counter = 0, testCounterVar = 0;
-
- int yAxisGlobal = 5;
- int dashHeight; // Height of Dashboard
- int dashWidth; // Width of Dashboard
- long accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);
- operation_mode mode1=Master; //Working Mode
-
- order order_array[];
- long lastFileSize=0;
- datetime lastModified=0;
- string symbolExclude = ""; // Symbol to Exclude
- string mappingSymbol = ""; // Mapping Pairs Inp,Out;Inp,Out
- int OnInit()
- {
- //---
- trade.SetExpertMagicNumber(magic_no);
- trade.SetDeviationInPoints(10);
- trade.SetTypeFilling(ORDER_FILLING_IOC);
- trade.LogLevel(LOG_LEVEL_ALL);
- trade.SetAsyncMode(false);
-
- if(!ObjectFind(0,"mode") || ObjectGetString(0,"mode",OBJPROP_TEXT,0)!=EnumToString(mode1)+" Account")
- {
- ObjectDelete(0,"mode");
- ObjectCreate(0,"mode",OBJ_LABEL,0,0,0);
- ObjectSetInteger(0,"mode",OBJPROP_XDISTANCE,10);
- ObjectSetInteger(0,"mode",OBJPROP_YDISTANCE,25);
- ObjectSetInteger(0,"mode",OBJPROP_CORNER,CORNER_RIGHT_UPPER);
- ObjectSetInteger(0,"mode",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
- ObjectSetInteger(0,"mode",OBJPROP_COLOR,clrLightBlue);
- ObjectSetString(0,"mode",OBJPROP_TEXT,EnumToString(mode1)+" Account");
- ObjectSetInteger(0,"mode",OBJPROP_FONTSIZE,14);
- }
-
- dashHeight = DashHeight;
- dashWidth = DashWidth;
- double width = double(ChartGetInteger(0,CHART_WIDTH_IN_PIXELS));
- double height = double(ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS));
-
- double minHeight = (110/height) * (height);
- double minWidth = (480.0/width) * (width);
-
- Print(" Minimum Required minHeight = ",minHeight," minWidth ",minWidth);
-
- if(dashWidth < minWidth)
- {
- dashWidth = (int)minWidth;
- Print(" Dashboard width is updated because user input is less than required width ");
- }
- if(dashHeight < minHeight)
- {
- dashHeight = (int)minHeight;
- Print(" Dashboard Height is updated because user input is less than required Height ");
- }
-
- if(!ExtDialog.Create(0,"Local Hedge Master",10,10,40,dashWidth,dashHeight)) // the panel position
- return(INIT_FAILED);
- ExtDialog.Run();
-
- gmtDifference = (int)TimeCurrent() - (int)TimeGMT();
- Print("GMT Difference(sec): ",gmtDifference);
-
- EventSetMillisecondTimer(500);
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //---
- ExtDialog.Destroy(reason);
- EventKillTimer();
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTimer()
- {
- gmtDifference = (int)TimeCurrent() - (int)TimeGMT();
-
- dashboard_data();
-
- remove_old_tickets_from_store();
- store_live_and_history_tickets();
-
- writeData();
- readDataCofClient();
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- //---
-
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnChartEvent(const int id,
- const long &lparam,
- const double &dparam,
- const string &sparam)
- {
- //---
- ExtDialog.ChartEvent(id,lparam,dparam,sparam);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void readDataCofClient()
- {
- int fileHandleClient = 0;
- fileHandleClient = FileOpen("COF_client.csv",
- FILE_SHARE_READ|FILE_CSV|FILE_COMMON|FILE_READ|FILE_ANSI|FILE_TXT|FILE_COMMON);
-
- if(fileHandleClient != INVALID_HANDLE)
- {
- datetime lastFileModified = (datetime)FileGetInteger(fileHandleClient, FILE_MODIFY_DATE);
- long fileSize = FileGetInteger(fileHandleClient, FILE_SIZE);
-
- if(lastModified == lastFileModified && fileSize == lastFileSize)
- {
- FileClose(fileHandleClient);
- }
- else
- {
- clearOrderArray();
-
- while(!FileIsEnding(fileHandleClient))
- {
- string OrderToRead = FileReadString(fileHandleClient);
- string Order_specs[];
- StringSplit(OrderToRead, StringGetCharacter(",", 0), Order_specs);
-
- Print("Array Size: ", ArraySize(Order_specs));
-
- if(ArraySize(Order_specs) == 11 || ArraySize(Order_specs) == 12)
- {
- string symbol = getSymbol(Order_specs[1]);
- int orderType = StringToInteger(Order_specs[2]);
-
- //if(StringFind(symbol, symbolExclude, 0) < 0 &&
- // (((orderType == POSITION_TYPE_BUY || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_SELL_STOP) && (tradeType == 0 || tradeType == 2)) ||
- // ((orderType == POSITION_TYPE_SELL || orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_SELL_LIMIT) && (tradeType == 1 || tradeType == 2))))
- {
- order_array[ArraySize(order_array)-1].symbol = symbol;
- order_array[ArraySize(order_array)-1].opentime = StringToTime(Order_specs[0]);
- order_array[ArraySize(order_array)-1].price = StringToDouble(Order_specs[3]);
- order_array[ArraySize(order_array)-1].ordertype = orderType;
- order_array[ArraySize(order_array)-1].lots = StringToDouble(Order_specs[4]);
- order_array[ArraySize(order_array)-1].stoploss = StringToDouble(Order_specs[5]);
- order_array[ArraySize(order_array)-1].takeprofit = StringToDouble(Order_specs[6]);
- order_array[ArraySize(order_array)-1].ticket = StringToInteger(Order_specs[7]);
- order_array[ArraySize(order_array)-1].magicNo = StringToInteger(Order_specs[8]);
- order_array[ArraySize(order_array)-1].accountBalance = StringToDouble(Order_specs[9]);
- order_array[ArraySize(order_array)-1].contractSize = StringToInteger(Order_specs[10]);
-
- if(ArraySize(Order_specs) == 12)
- order_array[ArraySize(order_array)-1].comments = Order_specs[11];
- else
- order_array[ArraySize(order_array)-1].comments = "";
-
- if(ArraySize(Order_specs) == 12)
- {
- StringReplace(Order_specs[11], "from #", "");
- StringReplace(Order_specs[11], " ", "");
-
- Print(" Order_specs[11] ", Order_specs[11],
- " order_array ticket ", order_array[ArraySize(order_array)-1].ticket);
-
- //for(int l = 0; l < orderCount; l++)
- // {
- // if(cod[l].magic == int(Order_specs[11]))
- // cod[l].magic = order_array[ArraySize(order_array)-1].ticket;
- // }
- }
-
- //for(int i = 0 ; i < ArraySize(Order_specs) ; i++)
- // {
- // Print("Order_specs[", i, "] = ", Order_specs[i]);
- // }
- Print(" | Client Magic: ", order_array[ArraySize(order_array)-1].magicNo,
- " | Client Ticket: ", order_array[ArraySize(order_array)-1].ticket,
- " | Symbol: ", order_array[ArraySize(order_array)-1].symbol,
- " | Open Price: ", order_array[ArraySize(order_array)-1].price,
- " | Lot: ", order_array[ArraySize(order_array)-1].lots,
- " | Open time: ", order_array[ArraySize(order_array)-1].opentime);
-
- ArrayResize(order_array, ArraySize(order_array) + 1);
- }
- }
- }
-
- lastModified = lastFileModified;
- lastFileSize = fileSize;
- FileClose(fileHandleClient);
- }
- }
-
-
- // Order Operations
- int arraySize=ArraySize(order_array);
- if(ArraySize(order_array) == 1) //
- {
- if(PositionsTotal() > 0)
- {
- for(int i=PositionsTotal()-1; i>=0; i--)
- {
- ulong ticket = PositionGetTicket(i);
- if(PositionSelectByTicket(ticket))
- {
- if(history_ticket_present(PositionGetInteger(POSITION_MAGIC)))
- if(!trade.PositionClose(ticket))
- {
- Print(" Order Close Error on No Master Trade: "+IntegerToString(GetLastError()));
- }
- else
- Print(" ------------- Order Close by empty array ------------------ ");
- }
- }
- }
- if(OrdersTotal() > 0)
- {
- for(int i=OrdersTotal()-1; i>=0; i--)
- {
- ulong ticket = OrderGetTicket(i);
- if(OrderSelect(ticket))
- {
- if(history_ticket_present(OrderGetInteger(ORDER_MAGIC)))
- if(!trade.OrderDelete(ticket))
- {
- Print(" Error in Deleting Pending Order (Empty Array) : "+IntegerToString(GetLastError()));
- }
- else
- Print("Order Close by empty array (Empty Array)");
- }
- }
- }
- deleteAllArray();
- }
- else
- {
- for(int i=0; i<ArraySize(order_array); i++)
- {
- //Print(" Magic Number: ", order_array[i].magicNo, " Index: ", i);
- int trade_taken = 2;
- int partialCloseOrderPosition=-1;
-
- int index = -1;
- for(int j=0; j<orderCount; j++)
- {
- //if(OrderSelect(cod[j].ticket,SELECT_BY_POS))
- if(cod[j].ticket!=-1)
- {
- // select order directly by magic number
- if(PositionSelectByTicket(cod[j].magic)) // ==
- {
- Print(" Client Magic Number is: ", cod[j].magic);
- trade_taken = 0;
- }
-
- if(cod[j].magic==order_array[i].ticket)
- {
- if(cod[j].masterLot != order_array[i].lots)
- {
- Print(" Cod Lot Size: ", cod[j].masterLot, " Order Array Lot: ", order_array[i].lots);
- Print("Order is partial close:",cod[j].magic);
- trade_taken=1;
- partialCloseOrderPosition=j;
- }
- }
- }
- }
- if(order_array[i].ticket != -1)
- {
- if(trade_taken==1)
- {
- //current order need to close partially
- if(partialCloseOrderPosition!=-1)
- {
- bool isOrderClose=false;
- if(cod[partialCloseOrderPosition].masterLot <= 0)
- {
- Print("Error: Invalid masterLot for partial close");
- continue;
- }
- //if(OrderSelect(partialCloseOrderPosition,SELECT_BY_TICKET))
- {
- Print("Master lot: ",order_array[i].lots," last save lot: ",cod[partialCloseOrderPosition].masterLot);
- double lotClosePer = NormalizeDouble(100 - (order_array[i].lots/cod[partialCloseOrderPosition].masterLot*100),2);
- Print("Order in master is closed in percentage: ",lotClosePer," last client lot: ",cod[partialCloseOrderPosition].lots);
- double closeLot=NormalizeDouble(lotClosePer/100 *cod[partialCloseOrderPosition].lots,2);
- Print("Close lot in client: ",closeLot);
- if(!trade.PositionClosePartial(cod[partialCloseOrderPosition].ticket,closeLot))
- {
- Print("Partial order did not close:",cod[partialCloseOrderPosition].ticket);
- }
- else
- {
- isOrderClose=true;
- cod[partialCloseOrderPosition].lots=cod[partialCloseOrderPosition].lots-closeLot; //PositionGetDouble(POSITION_VOLUME);
- cod[partialCloseOrderPosition].masterLot = order_array[i].lots;
- }
- }
- }
- }
- else
- if(trade_taken == 2)
- {
- if(order_array[ArraySize(order_array)-1].magicNo > 0 && order_array[ArraySize(order_array)-1].magicNo != -1)
- {
- // cod[index].opentime=order_array[i].opentime;
- // cod[index].symbol=order_array[i].symbol;
- // cod[index].ordertype=order_array[i].ordertype;
- // cod[index].price=order_array[i].price;
- // cod[index].lots=order_array[i].lots;
- // cod[index].stoploss=order_array[i].stoploss;
- // cod[index].takeprofit=order_array[i].takeprofit;
- // cod[index].ticket=order_array[i].ticket;
- // cod[index].magic=order_array[i].magicNo;
- // //mod1[i].comment=PositionGetString(POSITION_COMMENT);
- //
- // Print(" Ticket Added Client -> Master Magic: ", order_array[i].magicNo,
- // " | Client Ticket: ", order_array[i].ticket,
- // " | Symbol: ", order_array[i].symbol,
- // " | Open Price: ", order_array[i].price,
- // " | Lot: ", order_array[i].lots,
- // " | Open time: ", order_array[i].opentime);
- }
- }
- }
- }
-
- // for(int i=0; i<orderCount; i++)
- // {
- // bool trade_close = true;
- // if(PositionSelectByTicket(cod[i].ticket))
- // {
- //
- // for(int j=0; j<ArraySize(order_array); j++)
- // {
- // if(cod[i].magic == (order_array[j].ticket))
- // {
- //
- // trade_close = false;
- // if(PositionGetDouble(POSITION_TP)!=order_array[j].takeprofit || PositionGetDouble(POSITION_SL)!=order_array[j].stoploss)
- // {
- //
- // if(trade.PositionModify(PositionGetInteger(POSITION_TICKET),order_array[j].stoploss,order_array[j].takeprofit))
- // {
- // Print("Order modified ticket:",PositionGetInteger(POSITION_TICKET));
- // cod[i].takeprofit=order_array[j].takeprofit;
- // cod[i].stoploss=order_array[j].stoploss;
- // }
- // else
- // {
- // Print("Order not modified error:",GetLastError());
- // }
- // }
- // }
- // }
- // if(trade_close == true)
- // {
- // if(PositionGetInteger(POSITION_TYPE)== ORDER_TYPE_BUY)
- // {
- // if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
- // {
- // Print("Buy Order Close Error on Master Trade Close: "+IntegerToString(GetLastError()));
- // }
- // else
- // {
- // Print("Order close by no master copy of trade");
- // cod[i].ticket=-1;
- // }
- // }
- // if(PositionGetInteger(POSITION_TYPE)== ORDER_TYPE_SELL)
- // {
- // if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
- // {
- // Print("Sell Order Close Error on Master Trade Close: "+IntegerToString(GetLastError()));
- // }
- // else
- // {
- // Print("Order close by no master copy of trade");
- // cod[i].ticket=-1;
- // }
- // }
- // }
- // }
- //
- // if(OrderSelect(cod[i].ticket))
- // {
- // for(int j=0; j<ArraySize(order_array); j++)
- // {
- // if(cod[i].magic == (order_array[j].ticket))
- // {
- //
- // trade_close = false;
- // if(OrderGetDouble(ORDER_TP)!=order_array[j].takeprofit || OrderGetDouble(ORDER_SL)!=order_array[j].stoploss || OrderGetDouble(ORDER_PRICE_OPEN)!=order_array[j].price)
- // {
- // if(trade.OrderModify(OrderGetInteger(ORDER_TICKET),order_array[j].price,order_array[j].stoploss,order_array[j].takeprofit, 0, 0, 0))
- // {
- // Print("Pending Order modified ticket:",PositionGetInteger(POSITION_TICKET));
- // cod[i].takeprofit=order_array[j].takeprofit;
- // cod[i].stoploss=order_array[j].stoploss;
- // cod[i].price = order_array[j].price;
- // }
- // else
- // {
- // Print("Order not modified error:",GetLastError());
- // }
- // }
- // }
- // }
- // if(trade_close == true)
- // {
- // if(OrderGetInteger(ORDER_TYPE)== ORDER_TYPE_BUY_STOP || OrderGetInteger(ORDER_TYPE)== ORDER_TYPE_SELL_STOP || OrderGetInteger(ORDER_TYPE)== ORDER_TYPE_BUY_LIMIT || OrderGetInteger(ORDER_TYPE)== ORDER_TYPE_SELL_LIMIT)
- // {
- // if(!trade.OrderDelete(OrderGetInteger(ORDER_TICKET)))
- // {
- // Print("Error in Deleting Pending Order: "+IntegerToString(GetLastError()));
- // }
- // else
- // {
- // Print("Pending Order Deleted. Ticket is: ", cod[i].ticket);
- // cod[i].ticket=-1;
- // }
- // }
- // }
- // }
- // }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void writeData()
- {
- if(PositionsTotal()==0 && OrdersTotal() == 0 && !fileLastEmpty && TerminalInfoInteger(TERMINAL_CONNECTED)) // && IsConnected()
- {
- filehandle=FileOpen("COF.csv",FILE_WRITE|FILE_CSV|FILE_COMMON);
- if(filehandle!=INVALID_HANDLE)
- {
- Print("Writing file to empty");
- FileWrite(filehandle,"");
- FileClose(filehandle);
- fileLastEmpty=true;
- emptyStruct();
- }
- else
- {
- Print("File handler issue:",GetLastError());
- }
-
- }
- else
- {
- bool updationReq=checkOrderUpdate();
- if(updationReq || fileHandlerIssue)
- {
- filehandle=FileOpen("COF.csv",FILE_WRITE|FILE_CSV|FILE_COMMON);
- if(filehandle!=INVALID_HANDLE)
- {
- fileHandlerIssue=false;
- for(int i = PositionsTotal()-1 ; i >= 0 ; i--)
- {
- ulong ticket = PositionGetTicket(i);
- if(PositionSelectByTicket(ticket))
- {
- if(((useMinimumLot && (PositionGetDouble(POSITION_VOLUME) > minimumLot))||!useMinimumLot) &&
- ((useMaximumLot && (PositionGetDouble(POSITION_VOLUME) < maximumLot)) || !useMaximumLot))
- {
- string time = TimeToString(PositionGetInteger(POSITION_TIME)-gmtDifference,TIME_DATE|TIME_SECONDS);
- string symbol = PositionGetString(POSITION_SYMBOL);
- double digits=getDoubleSymbolInfo(symbol,"digits");
-
- int symbolContractSize=(int)getDoubleSymbolInfo(symbol,"contract");
-
- ulong tempTicket = PositionGetInteger(POSITION_TICKET);
-
- if(suffix != "")
- symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
- if(prefix != "")
- StringReplace(symbol, prefix, "");
-
-
- long orderType = PositionGetInteger(POSITION_TYPE);
- double takeProfit = PositionGetDouble(POSITION_TP), stopLoss = PositionGetDouble(POSITION_SL);
- if(doReversal)
- {
- if(orderType == POSITION_TYPE_BUY)
- orderType = POSITION_TYPE_SELL;
- else
- if(orderType == POSITION_TYPE_SELL)
- orderType = POSITION_TYPE_BUY;
-
- takeProfit = PositionGetDouble(POSITION_SL);
- stopLoss = PositionGetDouble(POSITION_TP);
- }
-
- string OrderToWrite = time+","+symbol+","+IntegerToString(orderType)+","+DoubleToString(PositionGetDouble(POSITION_PRICE_OPEN), (int)digits)+","+DoubleToString(PositionGetDouble(POSITION_VOLUME),2)+","+DoubleToString(stopLoss,(int) digits)+","+DoubleToString(takeProfit, (int) digits)+","+IntegerToString(PositionGetInteger(POSITION_TICKET))+","+IntegerToString(PositionGetInteger(POSITION_MAGIC))+","+(string)AccountInfoDouble(ACCOUNT_BALANCE)+","+(string)SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_TRADE_CONTRACT_SIZE)+PositionGetString(POSITION_COMMENT)+"\r\n";
-
- FileWrite(filehandle,OrderToWrite);
- }
- }
- }
-
- for(int i = OrdersTotal()-1 ; i >= 0 ; i--)
- {
- ulong ticket = OrderGetTicket(i);
- if(OrderSelect(ticket))
- {
- if(((useMinimumLot && (OrderGetDouble(ORDER_VOLUME_CURRENT) > minimumLot))||!useMinimumLot) &&
- ((useMaximumLot && (OrderGetDouble(ORDER_VOLUME_CURRENT) < maximumLot))||!useMaximumLot))
- {
- string time = TimeToString(OrderGetInteger(ORDER_TIME_SETUP)-gmtDifference,TIME_DATE|TIME_SECONDS);
- string symbol = OrderGetString(ORDER_SYMBOL);
- double digits=getDoubleSymbolInfo(symbol,"digits");
-
- int symbolContractSize=(int)getDoubleSymbolInfo(symbol,"contract");
-
- ulong tempTicket = OrderGetInteger(ORDER_TICKET);
-
- if(suffix != "")
- symbol = StringSubstr(symbol, 0, StringFind(symbol, suffix, 0));
- if(prefix != "")
- StringReplace(symbol, prefix, "");
-
- long orderType = OrderGetInteger(ORDER_TYPE);
- double takeProfit = OrderGetDouble(ORDER_TP), stopLoss = OrderGetDouble(ORDER_SL);
-
- if(doReversal)
- {
- if(orderType == ORDER_TYPE_BUY_STOP)
- orderType = ORDER_TYPE_SELL_LIMIT;
- else
- if(orderType == ORDER_TYPE_SELL_STOP)
- orderType = ORDER_TYPE_BUY_LIMIT;
- else
- if(orderType == ORDER_TYPE_BUY_LIMIT)
- orderType = ORDER_TYPE_SELL_STOP;
- else
- if(orderType == ORDER_TYPE_SELL_LIMIT)
- orderType = ORDER_TYPE_BUY_STOP;
-
- takeProfit = OrderGetDouble(ORDER_SL);
- stopLoss = OrderGetDouble(ORDER_TP);
- }
-
-
- string OrderToWrite = time+","+symbol+","+IntegerToString(orderType)+","+DoubleToString(OrderGetDouble(ORDER_PRICE_OPEN), (int)digits)+","+DoubleToString(OrderGetDouble(ORDER_VOLUME_CURRENT),2)+","+DoubleToString(stopLoss,(int) digits)+","+DoubleToString(takeProfit, (int) digits)+","+IntegerToString(OrderGetInteger(ORDER_TICKET))+","+IntegerToString(OrderGetInteger(ORDER_MAGIC))+","+(string)AccountInfoDouble(ACCOUNT_BALANCE)+","+(string)SymbolInfoDouble(OrderGetString(ORDER_SYMBOL),SYMBOL_TRADE_CONTRACT_SIZE)+OrderGetString(ORDER_COMMENT)+"\r\n";
- Print("Writing Pending Order Block.");
- FileWrite(filehandle,OrderToWrite);
- }
- }
- }
- FileClose(filehandle);
- fileLastEmpty=false;
- Print("File Updated:",TimeCurrent());
- }
- else
- {
- Print("File Handle Issue: ", GetLastError());
- }
- }
- else
- {
- if(counter>=count1 && TerminalInfoInteger(TERMINAL_CONNECTED))
- {
-
- if(testCounterVar>=testCounter)
- {
- testCounterVar=0;
- }
- adminHeartBeat();
- counter=0;
-
- }
- counter++;
- testCounterVar++;
- }
-
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void adminHeartBeat()
- {
-
- string headers = "apikey:"+localApiKey+"\r\naccept: */* \r\nContent-Type: application/json\r\nUser-Agent: MetaTraderApi";
-
- string url =localHB_req_link;// Request_link+(string)accountNumber;
-
- bool isPost;
- int timeout = 100000;
- string lastConnected=TimeToString(TimeCurrent());
-
- StringReplace(lastConnected,".","-");
- StringReplace(lastConnected," ","T");
- string gmtTime=TimeToString(TimeGMT());
-
- string jsonData="{\"mLogin\":\""+(string)accountNumber+"\",\"mServer\":\""+masterServer+"\",\"mVersion\":\"5\" ,\"sLogin\":\""+slaveId+"\",\"sServer\":\""+slaveServer+"\",\"sVersion\":\""+slaveVersion+"\" ,\"mLastConnected\":\""+gmtTime+"\"}";//\",\"url\":"+"\""+url+"\""+headers+"}";
-
- uchar data[];
- StringToCharArray(jsonData, data, 0, StringLen(jsonData));
-
-
- // Print("Making the heart beat request to the local host");
- POST_function(url,headers,timeout,data,isPost);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool POST_function(string url, string headers, int timeout, uchar &data[], bool &IsPost)
- {
- ResetLastError(); // clear previous error
- static int lastErrorPrinted = 0;
- uchar result[]; // use uchar for WebRequest result
- string resultHeaders;
-
- int res = WebRequest("POST", url, headers, timeout, data, result, resultHeaders);
-
- if(res == 200 || res == 201)
- {
- Print("***Request success. HTTP response code POST: ", res);
- string result_string = CharArrayToString(result);
- Print("content POST: ", result_string);
- lastErrorPrinted = 0; // reset remembered error on success
- IsPost = true;
- return true;
- }
- else
- {
- int err = GetLastError(); // read the error once
- // only print when there's a real error and it's different from last time
- if(err != 0 && err != lastErrorPrinted)
- {
- Print("Get last error: ", err);
- Print("***Request failed. HTTP response code: ", res);
- string result_string = CharArrayToString(result);
- Print("content: ", result_string);
- lastErrorPrinted = err; // remember this error so we don't spam it
- }
- IsPost = false;
- return false;
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void removeDeleteOrderMaster()
- {
- for(int i=0; i<orderCount; i++)
- {
- bool isPresent=false;
- if(mod1[i].ticket!=-1)
- {
- for(int j = PositionsTotal()-1; j>=0; j--)
- {
- ulong ticket = PositionGetTicket(j);
- if(PositionSelectByTicket(ticket))
- {
- if(ticket==mod1[i].ticket)
- {
- isPresent=true;
- }
- }
- }
- if(!isPresent)
- {
- Print("The order ticket:",mod1[i].ticket," found no more");
- //delete from list
- mod1[i].ticket=-1;
- }
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void clearOrderArray()
- {
- //Resize to one
- ArrayResize(order_array,1);
- //Clear all data
- order_array[0].symbol = "";
- order_array[0].opentime = 0;
- order_array[0].price = 0;
- order_array[0].ordertype = 0;
- order_array[0].lots = 0;
- order_array[0].stoploss = 0;
- order_array[0].takeprofit = 0;
- order_array[0].ticket = -1;
- order_array[0].magicNo = 0;
- order_array[0].accountBalance=0;
- order_array[0].contractSize=0;
- order_array[0].comments="";
-
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void deleteAllArray()
- {
- for(int i=0; i<orderCount; i++)
- {
- if(cod[i].ticket!=-1)
- {
- cod[i].ticket=-1;
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool checkorderpips(double openPrice,int type,string symbol)
- {
- double points = inpPips*10*SymbolInfoDouble(symbol,SYMBOL_POINT);
- if(type == 0)
- {
- if(SymbolInfoDouble(symbol,SYMBOL_ASK) - openPrice > points)
- {
- return true;
- }
- }
- else
- {
- if(openPrice - SymbolInfoDouble(symbol,SYMBOL_BID) > points)
- {
- return true;
- }
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool isOrderThere(ulong ticket,int &index)
- {
- for(int i=0; i<ArraySize(mod1); i++)
- {
- if(ticket != -1)
- {
- if(mod1[i].ticket==ticket)
- {
- index=i;
- return true;
- }
- }
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool addOrderMaster(ulong ticket, string calledBy)
- {
- for(int i=0; i<ArraySize(mod1); i++)
- {
- if(mod1[i].ticket==-1)
- {
-
- if(calledBy == "Market")
- {
- //ulong ticket = PositionGetTicket(orderTicket);
- if(PositionSelectByTicket(ticket))
- {
- //Symbol Updation
- string symbol=PositionGetString(POSITION_SYMBOL);
- if(suffix!="")
- symbol = StringSubstr(symbol,0,StringFind(PositionGetString(POSITION_SYMBOL),suffix,0));
- if(prefix!="")
- StringReplace(symbol,prefix,"");
-
- //Digits
- double digits=getDoubleSymbolInfo(PositionGetString(POSITION_SYMBOL),"digits");
-
- //time
- datetime time = (datetime)(PositionGetInteger(POSITION_TIME)-gmtDifference);
-
- mod1[i].opentime=time;
- mod1[i].symbol=symbol;
- mod1[i].ordertype=PositionGetInteger(POSITION_TYPE);
- mod1[i].price=NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN),(int)digits);
- mod1[i].lots=NormalizeDouble(PositionGetDouble(POSITION_VOLUME),2);
- mod1[i].stoploss=NormalizeDouble(PositionGetDouble(POSITION_SL),(int)digits);
- mod1[i].takeprofit=NormalizeDouble(PositionGetDouble(POSITION_TP),(int)digits);
- mod1[i].ticket=PositionGetInteger(POSITION_TICKET);
- mod1[i].magic=(int)PositionGetInteger(POSITION_MAGIC);
- mod1[i].comment=PositionGetString(POSITION_COMMENT);
- Print("Ticket:",PositionGetInteger(POSITION_TICKET)," stored in index:",i);
- return true;
- }
- }
- if(calledBy == "Pending")
- {
- if(OrderSelect(ticket))
- {
- string symbol = OrderGetString(ORDER_SYMBOL);
- if(suffix!="")
- symbol = StringSubstr(symbol,0,StringFind(OrderGetString(ORDER_SYMBOL),suffix,0));
- if(prefix!="")
- StringReplace(symbol,prefix,"");
-
- //Digits
- double digits=getDoubleSymbolInfo(OrderGetString(ORDER_SYMBOL),"digits");
-
- //time
- datetime time = (datetime)(OrderGetInteger(ORDER_TIME_SETUP) - gmtDifference);
-
- mod1[i].opentime=time;
- mod1[i].symbol=symbol;
- mod1[i].ordertype=OrderGetInteger(ORDER_TYPE);
- mod1[i].price=NormalizeDouble(OrderGetDouble(ORDER_PRICE_OPEN),(int)digits);
- mod1[i].lots=NormalizeDouble(OrderGetDouble(ORDER_VOLUME_CURRENT),2);
- mod1[i].stoploss=NormalizeDouble(OrderGetDouble(ORDER_SL),(int)digits);
- mod1[i].takeprofit=NormalizeDouble(OrderGetDouble(ORDER_TP),(int)digits);
- mod1[i].ticket=OrderGetInteger(ORDER_TICKET);
- mod1[i].magic=(int)OrderGetInteger(ORDER_MAGIC);
- mod1[i].comment=OrderGetString(ORDER_COMMENT);
- Print("Ticket: ",OrderGetInteger(ORDER_TICKET)," stored in index by pending order:",i);
- return true;
- }
- }
- }
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void emptyStruct()
- {
- for(int i = 0 ; i < orderCount ; i++)
- {
- if(mod1[i].ticket != -1)
- {
- mod1[i].ticket=-1;
- mod1[i].price=-1;
- mod1[i].symbol="";
- mod1[i].ordertype=-1;
- mod1[i].lots=0;
- mod1[i].stoploss=0;
- mod1[i].takeprofit=0;
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool checkOrderUpdate()
- {
- bool updationRequired=false,currCheck=false;
- for(int i = PositionsTotal()-1 ; i >= 0 ; i--)
- {
- ulong ticket = PositionGetTicket(i);
- if(PositionSelectByTicket(ticket))
- {
- int orderIndex=-1;
- bool alreadyAdded=isOrderThere(ticket, orderIndex);
- if(!alreadyAdded)
- {
- currCheck=false;
- currCheck=addOrderMaster(ticket, "Market");
- if(!updationRequired)
- updationRequired=currCheck;
- }
- else
- {
- if(orderIndex!=-1)
- {
- currCheck=false;
- currCheck=IsOrderChanged(PositionGetInteger(POSITION_TICKET),orderIndex, "Market");
- if(!updationRequired)
- {
- updationRequired=currCheck;
- }
- }
- }
- }
- }
-
-
- for(int i = OrdersTotal()-1 ; i >= 0 ; i--)
- {
- ulong ticket = OrderGetTicket(i);
- if(OrderSelect(ticket))
- {
- if(OrderGetInteger(ORDER_TYPE) != ORDER_TYPE_BUY && OrderGetInteger(ORDER_TYPE) != ORDER_TYPE_SELL && OrderGetInteger(ORDER_TYPE) != ORDER_TYPE_CLOSE_BY)
- {
- int orderIndex=-1;
- bool alreadyAdded=isOrderThere(ticket, orderIndex);
- if(!alreadyAdded)
- {
- Print("Inside pending Adding to master order: ",ticket," type: ",OrderGetInteger(ORDER_TYPE)," ",OrdersTotal()," ",ORDER_TYPE_CLOSE_BY);
- currCheck=false;
- currCheck=addOrderMaster(ticket, "Pending");
- if(!updationRequired)
- updationRequired=currCheck;
- }
- else
- {
- if(orderIndex!=-1)
- {
- currCheck=false;
-
- currCheck=IsOrderChanged(OrderGetInteger(ORDER_TICKET), orderIndex, "Pending");
- if(!updationRequired)
- {
- updationRequired=currCheck;
- }
- }
- }
- }
- }
- }
-
- for(int i=0; i<ArraySize(mod1); i++)
- {
- bool isPresent=false;
- if(mod1[i].ticket !=-1)
- {
- for(int j = PositionsTotal()-1; j>=0; j--)
- {
- ulong ticket = PositionGetTicket(j);
- if(PositionSelectByTicket(ticket))
- {
- if(ticket==mod1[i].ticket)
- {
- isPresent=true;
- break;
- }
- }
- }
- // Pending Order
- for(int j = OrdersTotal()-1; j>=0; j--)
- {
- ulong ticket = OrderGetTicket(j);
- if(OrderSelect(ticket))
- {
- if(ticket==mod1[i].ticket)
- {
- isPresent=true;
- break;
- }
- }
- }
-
- if(!isPresent)
- {
- Print("Ticket is closed so removed from struct: ",mod1[i].ticket);
- mod1[i].ticket=-1;
- mod1[i].price=-1;
- mod1[i].symbol="";
- mod1[i].ordertype=-1;
- mod1[i].lots=0;
- mod1[i].stoploss=0;
- mod1[i].takeprofit=0;
- currCheck=true;
- //currCheck=clearStructIndex(mod1[i].ticket);
- if(!updationRequired)
- updationRequired=currCheck;
- }
- }
- }
- return updationRequired;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool clearStructIndex(ulong ticket)
- {
- for(int index=0; index<ArraySize(mod1); index++)
- {
- if(mod1[index].ticket == ticket)
- {
- mod1[index].ticket=-1;
- mod1[index].price=-1;
- mod1[index].symbol="";
- mod1[index].ordertype=-1;
- mod1[index].lots=0;
- mod1[index].stoploss=0;
- mod1[index].takeprofit=0;
- Print("Clear Structure Called. ");
- return true;
- }
- }
-
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool IsOrderChanged(ulong orderTicket, int index, string calledBy)
- {
- if(mod1[index].ticket!=-1)
- {
- if(calledBy == "Market")
- {
-
- if(PositionSelectByTicket(orderTicket))
- {
- //Digits
- double digits=getDoubleSymbolInfo(PositionGetString(POSITION_SYMBOL),"digits");
-
- double tp=NormalizeDouble(PositionGetDouble(POSITION_TP), (int)digits),
- sl=NormalizeDouble(PositionGetDouble(POSITION_SL),(int)digits),
- lot=NormalizeDouble(PositionGetDouble(POSITION_VOLUME),2);
-
- if(mod1[index].takeprofit!=tp || mod1[index].stoploss != sl || mod1[index].lots!=lot || mod1[index].ordertype!=PositionGetInteger(POSITION_TYPE) || mod1[index].price != PositionGetDouble(POSITION_PRICE_OPEN))
- {
- Print(" Inside IsOrderChanged() ",mod1[index].lots," lot: ",lot," calledBy: ",calledBy," mod1 ticket ",mod1[index].ticket," orderTicket: ",orderTicket);
- // Time
- datetime time = (datetime)(PositionGetInteger(POSITION_TIME) - gmtDifference);
- mod1[index].opentime=time;
- mod1[index].lots=lot;
- mod1[index].stoploss=sl;
- mod1[index].takeprofit=tp;
- mod1[index].comment=PositionGetString(POSITION_COMMENT);
- mod1[index].ordertype=PositionGetInteger(POSITION_TYPE);
- mod1[index].price=PositionGetDouble(POSITION_PRICE_OPEN);
- return true;
- }
-
- }
- }
- if(calledBy == "Pending")
- {
- if(OrderSelect(orderTicket))
- {
- double digits=getDoubleSymbolInfo(OrderGetString(ORDER_SYMBOL),"digits");
-
- double tp=NormalizeDouble(OrderGetDouble(ORDER_TP), (int)digits),
- sl=NormalizeDouble(OrderGetDouble(ORDER_SL),(int)digits),
- lot=NormalizeDouble(OrderGetDouble(ORDER_VOLUME_CURRENT),2);
-
- if(mod1[index].takeprofit!=tp || mod1[index].stoploss != sl || mod1[index].lots!=lot || mod1[index].ordertype!=OrderGetInteger(ORDER_TYPE) || mod1[index].price != OrderGetDouble(ORDER_PRICE_OPEN))
- {
- //time
- datetime time = (datetime)(OrderGetDouble(ORDER_PRICE_OPEN) - gmtDifference);
- mod1[index].opentime=time;
- mod1[index].lots=lot;
- mod1[index].stoploss=sl;
- mod1[index].takeprofit=tp;
- mod1[index].comment=OrderGetString(ORDER_COMMENT);
- mod1[index].ordertype=OrderGetInteger(ORDER_TYPE);
- mod1[index].price=OrderGetDouble(ORDER_PRICE_OPEN);
- return true;
- }
- }
- }
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- double getlot(double stop_loss)
- {
- Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
- Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
- double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
- ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
- // Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
- double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
- // pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
- // pipvalue=
- pipvalue = pipvalue / 10;
- double lotSize = lot_size;
- if(lot_calculator==rsk) //calculating risk
- {
- double riskamount=(risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
- double pipvalue_required=riskamount/stop_loss;
- lotSize = pipvalue_required/pipvalue;
- //sl=riskamount/pipValuelot
- int roundDigit=0;
- double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
-
- while(step<1)
- {
- roundDigit++;
- step=step*10;
- }
- Print("Round Digits:",roundDigit);
- lotSize = NormalizeDouble(lotSize,roundDigit);
- //
- }
- Print("Lot Size: ",lotSize);
-
- if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
- {
- lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
- }
- else
- if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
- {
- lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
- }
-
- //---
- return lotSize;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- double getDoubleSymbolInfo(string symbol,string info)
- {
- long digits=8;
- //Symbol without the suffix and prefix
- string updatedSymbol=symbol;
- if(suffix!="")
- updatedSymbol = StringSubstr(updatedSymbol,0,StringFind(updatedSymbol,suffix,0));
- if(prefix!="")
- StringReplace(updatedSymbol,prefix,"");
-
- //Digits calculation could be used in other calculations
- digits = SymbolInfoInteger(symbol,SYMBOL_DIGITS);
- if(digits==0)
- {
- digits=SymbolInfoInteger(updatedSymbol,SYMBOL_DIGITS);
- if(digits==0)
- digits=8;
- }
-
- if(info=="digits")
- {
- return (double)digits;
- }
- else
- if(info=="point" || info=="points")
- {
- double points=SymbolInfoDouble(symbol, SYMBOL_POINT);
- if(points==0)
- {
- points=SymbolInfoDouble(updatedSymbol,SYMBOL_POINT);
- if(points==0)
- points=0.00001;
-
-
- }
- return points;
- }
- else
- if(info=="ask")
- {
- double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
- if(ask==0)
- {
- ask=SymbolInfoDouble(updatedSymbol,SYMBOL_ASK);
- }
- return NormalizeDouble(ask,(int)digits);
- }
- else
- if(info=="bid")
- {
- double bid=SymbolInfoDouble(symbol, SYMBOL_BID);
- if(bid==0)
- {
- bid=SymbolInfoDouble(updatedSymbol,SYMBOL_BID);
- }
- return NormalizeDouble(bid,(int)digits);
- }
- else
- if(info=="contract"||info=="contractSize")
- {
- double contract=SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE);
- if(contract==0)
- {
- contract=SymbolInfoDouble(updatedSymbol,SYMBOL_TRADE_CONTRACT_SIZE);
- }
- return contract;
- }
-
- return 0;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string getSymbol(string symbol)
- {
- if(mappingSymbol!="")
- {
- string symbollist[];
- StringSplit(mappingSymbol,';',symbollist);
- for(int i=0; i<ArraySize(symbollist); i++)
- {
- string symbolPairs[];
- StringSplit(symbollist[i],',',symbolPairs);
- if(ArraySize(symbolPairs)==2)
- {
- if(symbol==symbolPairs[0])
- return symbolPairs[1];
- }
- }
- }
- else
- {
- return prefix+symbol+suffix;
- }
-
- return prefix+symbol+suffix;
-
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void placeBuyTrade()
- {
-
- double buySL = 0, buyTp=0;
- //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
- double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
- double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
-
- if(stoplossTrade != 0)
- {
- buySL = Ask - (stoplossTrade * 10 * Point());
- }
- if(takeprofitTrade != 0)
- {
- buyTp = Ask + (takeprofitTrade * 10 * Point());
- }
-
- double sl_distance = ((Ask - buySL) / Point());
- if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(sl_distance),Ask,buySL,buyTp,"Buy Trade Placed"))
- {
- Print("Buy Trade Placed: ",trade.ResultOrder());
- }
- else
- {
- Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void placeSellTrade()
- {
-
- double sellSL = 0, sellTp = 0;
- //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
- double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
- double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
-
- if(stoplossTrade != 0)
- {
- sellSL = Bid + (stoplossTrade * 10 * Point());
- }
- if(takeprofitTrade != 0)
- {
- sellTp = Bid - (takeprofitTrade * 10 * Point());
- }
- double sl_distance = ((sellSL - Bid) / Point());
- if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(sl_distance),Bid,sellSL,sellTp,"Sell Trade Placed"))
- {
- Print("Sell Trade PLaced: ",trade.ResultOrder());
- }
- else
- {
- Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void dashboard_data()
- {
- ExtDialog.m_label0.Text(" Master Trades Lots Calc: " + DoubleToString(totalLiveLots(), 2));
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- double totalLiveLots()
- {
- double total_lots = 0.0;
-
- for(int i = 0; i < PositionsTotal(); i++)
- {
- ulong ticket = PositionGetTicket(i);
- if(PositionSelectByTicket(ticket))
- {
- //if(PositionGetInteger(POSITION_MAGIC) == magic_no)
- {
- //if(PositionGetString(POSITION_SYMBOL) == Symbol())
- {
- int type = (int)PositionGetInteger(POSITION_TYPE);
- if(type == POSITION_TYPE_BUY || type == POSITION_TYPE_SELL)
- {
- total_lots += PositionGetDouble(POSITION_VOLUME);
- }
- }
- }
- }
- }
- return total_lots;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void store_live_and_history_tickets()
- {
- // cutoff time = now - N days
- datetime cutoff = (datetime)(TimeCurrent() - (datetime)daysOfTradesToAdd * 86400);
-
- // --- history orders loop (closed / cancelled / executed orders) ---
- // select history for the required period
- if(HistorySelect(cutoff, TimeCurrent()))
- {
- int deals_count = (int)HistoryDealsTotal();
- for(int j = deals_count - 1; j >= 0; --j)
- {
- ulong deal_ticket = HistoryDealGetTicket(j);
- if(deal_ticket == 0)
- continue;
-
- // deal execution time
- long dealTime = (long)HistoryDealGetInteger(deal_ticket, DEAL_TIME);
- if((datetime)dealTime < cutoff)
- continue; // older than cutoff, skip
-
- // position id related to this deal (the stored "ticket" you track)
- long position_id = (long)HistoryDealGetInteger(deal_ticket, DEAL_POSITION_ID);
- if(position_id <= 0)
- continue; // no position id to store
-
- if(HistoryDealGetInteger(deal_ticket, DEAL_ENTRY) != DEAL_ENTRY_IN)
- continue;
-
- ulong ticket = position_id;
- ulong magic = HistoryDealGetInteger(deal_ticket, DEAL_MAGIC);
- double dealInLot = HistoryDealGetDouble(deal_ticket, DEAL_VOLUME);
-
- double dealOutLot = dealOutLotsCheck(cutoff, position_id);
- if(dealInLot == dealOutLot)
- if(!history_ticket_present(ticket))
- {
- Print(" Position Id: ", position_id," Deal In Lot: ", dealInLot, " Deal Out Lot: ", dealOutLot);
- add_history_ticket(ticket, magic);
- }
- }
- }
- else
- {
- // optional: failed to select history — you may handle/log if needed
- // Print("HistorySelect failed. LastError=", GetLastError());
- }
-
- int ordersTotal=HistoryOrdersTotal();
- ulong orderTicket=0;
- for(int j=0; j<ordersTotal; j++)
- {
- orderTicket=HistoryOrderGetTicket(j);
- long type=HistoryOrderGetInteger(orderTicket,ORDER_TYPE);
- if(type==ORDER_TYPE_BUY_LIMIT || type==ORDER_TYPE_SELL_LIMIT || type==ORDER_TYPE_BUY_STOP
- || type==ORDER_TYPE_SELL_STOP ||type==ORDER_TYPE_BUY_STOP_LIMIT || type==ORDER_TYPE_SELL_STOP_LIMIT)
- {
- long state=HistoryOrderGetInteger(orderTicket,ORDER_STATE);
- if(state==ORDER_STATE_CANCELED || state==ORDER_STATE_REJECTED || state==ORDER_STATE_EXPIRED || state==ORDER_STATE_REQUEST_CANCEL)
- {
- datetime openTime = (datetime)HistoryOrderGetInteger(orderTicket, ORDER_TIME_SETUP);
-
- if(openTime >= cutoff)
- {
- ulong magic = HistoryOrderGetInteger(orderTicket, ORDER_MAGIC);
-
- if(!history_ticket_present(orderTicket))
- {
- add_history_ticket(orderTicket, magic);
- }
- }
- }
- }
- }
-
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- double dealOutLotsCheck(datetime cutOffTimeIs, ulong positionId)
- {
- double sumOfLots = 0.0;
-
- if(HistorySelect(cutOffTimeIs, TimeCurrent()))
- {
- int totalDeals = HistoryDealsTotal();
-
- for(int i = 0; i < totalDeals; i++)
- {
- ulong dealTicket = HistoryDealGetTicket(i);
- ulong dealPositionID = (ulong)HistoryDealGetInteger(dealTicket, DEAL_POSITION_ID);
-
- if(HistoryDealGetInteger(dealTicket, DEAL_ENTRY) == DEAL_ENTRY_OUT
- && dealPositionID == positionId)
- {
- sumOfLots += HistoryDealGetDouble(dealTicket, DEAL_VOLUME);
- }
- }
- }
-
- return sumOfLots;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool history_ticket_present(ulong ticket)
- {
- for(int i = 0 ; i < MaxOrders ; i++)
- {
- if(historyTradeStore[i].ticket == ticket)
- return true;
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void add_history_ticket(ulong ticket, ulong magicIs)
- {
- for(int i = 0; i < MaxOrders; i++)
- {
- if(historyTradeStore[i].ticket == -1)
- {
- historyTradeStore[i].ticket = ticket;
- historyTradeStore[i].magic = magicIs;
- Print("Ticket Added to History Structure. Ticket: ", ticket, " Magic: ", magicIs);
- save_history_store("add_history_ticket()");
- return;
- }
- }
- Print("historyTradeStore full, cannot add ticket: ", ticket);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void clear_history_store()
- {
- for(int i = 0; i < MaxOrders; i++)
- {
- historyTradeStore[i].ticket = -1;
- historyTradeStore[i].magic = 0;
- }
- Print("History store cleaned");
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void save_history_store(string calledBy)
- {
- string file_nameIs = "history_trades.csv";
- int fileHandle = FileOpen(file_nameIs, FILE_WRITE | FILE_CSV | FILE_COMMON);
-
- if(fileHandle != INVALID_HANDLE)
- {
- for(int i = 0; i < MaxOrders; i++)
- {
- if(historyTradeStore[i].ticket != -1)
- {
- string data_to_store = IntegerToString(historyTradeStore[i].ticket) + "," + IntegerToString(historyTradeStore[i].magic) + "\r\n";
- FileWriteString(fileHandle, data_to_store);
- }
- }
-
- //Print("save_history_store() called by: ", calledBy, " Time: ", TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS));
- FileClose(fileHandle);
- }
- else
- {
- Print("Error opening file save_history_store(): ", GetLastError());
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void remove_old_tickets_from_store()
- {
- datetime cutoff = TimeCurrent() - (datetime)daysOfTradesToAdd * 86400;
- // Print("remove_old_tickets_from_store: cutoff = ", TimeToString(cutoff, TIME_DATE|TIME_SECONDS));
-
- // Prepare history selection ranges once (for deals we limit by cutoff; for orders we select full history)
-
- for(int i = 0; i < MaxOrders; i++)
- {
- ulong tk = historyTradeStore[i].ticket;
- if(tk == -1) // empty slot
- continue;
-
- bool found = false;
- ulong pos_ticket = (ulong)tk;
-
- if(HistorySelect(cutoff, TimeCurrent()))
- {
- int deals_count = (int)HistoryDealsTotal();
- for(int j = deals_count - 1; j >= 0; --j)
- {
- ulong deal_ticket = HistoryDealGetTicket(j);
- if(deal_ticket == 0)
- continue;
-
- // deal execution time
- long dealTime = (long)HistoryDealGetInteger(deal_ticket, DEAL_TIME);
- if((datetime)dealTime < cutoff)
- continue; // older than cutoff, skip
-
- if(HistoryDealGetInteger(deal_ticket, DEAL_ENTRY) != DEAL_ENTRY_IN)
- continue;
-
- // position id related to this deal (the stored "ticket" you track)
- long position_id = (long)HistoryDealGetInteger(deal_ticket, DEAL_POSITION_ID);
- if(position_id <= 0)
- continue; // no position id to store
- double dealInLot = HistoryDealGetDouble(deal_ticket, DEAL_VOLUME);
-
- double dealOutLot = dealOutLotsCheck(cutoff, position_id);
- if(dealInLot == dealOutLot)
- if(position_id == pos_ticket)
- {
- found = true;
- break;
- }
- }
- }
- else
- {
- // optional: failed to select history — you may handle/log if needed
- // Print("HistorySelect failed. LastError=", GetLastError());
- }
-
- if(!found)
- {
- int ordersTotal = HistoryOrdersTotal();
- for(int j = 0; j < ordersTotal; j++)
- {
- ulong orderTicket = HistoryOrderGetTicket(j);
- if(orderTicket == 0)
- continue;
-
- long type = HistoryOrderGetInteger(orderTicket, ORDER_TYPE);
- if(type != ORDER_TYPE_BUY_LIMIT && type != ORDER_TYPE_SELL_LIMIT &&
- type != ORDER_TYPE_BUY_STOP && type != ORDER_TYPE_SELL_STOP)
- continue;
-
- datetime openTime = (datetime)HistoryOrderGetInteger(orderTicket, ORDER_TIME_SETUP);
- long state=HistoryOrderGetInteger(orderTicket,ORDER_STATE);
- if(state==ORDER_STATE_CANCELED || state==ORDER_STATE_REJECTED || state==ORDER_STATE_EXPIRED || state==ORDER_STATE_REQUEST_CANCEL)
- {
- if(orderTicket == pos_ticket)
- {
- if(openTime > cutoff)
- {
- found = true;
- break;
- }
- }
- }
- }
- }
-
-
- // 3) Final action: remove if not found
- if(!found)
- {
- Print("Ticket not found, removing from store: ", tk, " index=", i);
- historyTradeStore[i].ticket = -1;
- historyTradeStore[i].magic = 0;
- // (optionally clear other fields if your struct has them)
- }
- } // for i
- }
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- //================================================ Dashboard ====================================
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- class CControlsDialog : public CAppDialog
- {
- public:
-
- CLabel m_label0;
-
- CButton m_button;
- CButton m_button1;
-
- CControlsDialog(void);
- ~CControlsDialog(void);
- //--- create
- virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
- virtual bool OnEvent(const int id, const long &lparam,const double &dparam, const string &sparam);
-
- bool CreateLabel0(void);
-
- bool CreateButton(void);
- bool CreateButton1(void);
-
- void OnClickButton(void);
- void OnClickButton1(void);
-
- bool CreatePanel(void);
-
- };
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- EVENT_MAP_BEGIN(CControlsDialog)
- ON_EVENT(ON_CLICK,m_button,OnClickButton)
- ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
- EVENT_MAP_END(CAppDialog)
- //+------------------------------------------------------------------+
- //| Constructor |
- //+------------------------------------------------------------------+
- CControlsDialog::CControlsDialog(void)
- {
- }
- //+------------------------------------------------------------------+
- //| Destructor |
- //+------------------------------------------------------------------+
- CControlsDialog::~CControlsDialog(void)
- {
- }
-
- //+------------------------------------------------------------------+
- //| Create |
- //+------------------------------------------------------------------+
- bool CControlsDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
- {
- if(!CAppDialog::Create(chart,name,subwin,20,20,dashWidth,dashHeight))
- return(false);
- //--- create dependent controls
-
- if(!CreatePanel())
- return(false);
-
- if(!CreateLabel0())
- return(false);
-
- if(!CreateButton())
- return(false);
- if(!CreateButton1())
- return(false);
-
- //--- succeed
- return(true);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool CControlsDialog::CreateLabel0(void) //Trend Info
- {
- //--- coordinates
- int x1 = (dashWidth/2) - 235;
- int y1 = yAxisGlobal + 15;
- int x2 = 0;
- int y2 = 0;
- //--- create
- if(!m_label0.Create(m_chart_id,m_name+"Label0",m_subwin,x1,y1,x2,y2))
- return(false);
- if(!m_label0.Text(" Master Trades Lots Calc: 0.00"))
- return(false);
- if(!m_label0.Color(clrBlack))
- return(false);
- if(!m_label0.Font("Calibri"))
- return(false);
- if(!m_label0.FontSize(FontSize))
- return(false);
- if(!Add(m_label0))
- return(false);
- //--- succeed
- return(true);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool CControlsDialog::CreateButton(void)
- {
- //--- coordinates
- // Buy
- int x1 = (dashWidth/2) + 14;
- int y1 = yAxisGlobal + 10;
- int x2 = x1 + 70;
- int y2 = y1 + 30;
- //--- create
- if(!m_button.Create(m_chart_id,"button",m_subwin,x1,y1,x2,y2))
- return(false);
- if(!m_button.ColorBackground(clrSlateGray))
- return(false);
- if(!m_button.Text("Sell"))
- return(false);
- if(!m_button.FontSize(FontSize))
- return(false);
- if(!m_button.ColorBackground(clrRed))
- return(false);
- if(!m_button.Font("Calibri Bold"))
- return(false);
- if(!m_button.Color(clrWhiteSmoke))
- return(false);
- if(!m_button.ColorBorder(clrRed))
- return(false);
- if(!Add(m_button))
- return(false);
- m_button.Locking(true);
- m_button.BringToTop();
- //--- succeed
- return(true);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool CControlsDialog::CreateButton1(void)
- {
- //--- coordinates
- // Sell
- int x1 = (dashWidth/2) + 100;
- int y1 = yAxisGlobal + 10;
- int x2 = x1 + 70;
- int y2 = y1 + 30;
- //--- create
- if(!m_button1.Create(m_chart_id,"button1",m_subwin,x1,y1,x2,y2))
- return(false);
- if(!m_button1.ColorBackground(clrBlue))
- return(false);
- if(!m_button1.Text("Buy"))
- return(false);
- if(!m_button1.FontSize(FontSize))
- return(false);
- if(!m_button1.Font("Calibri Bold"))
- return(false);
- if(!m_button1.Color(clrWhiteSmoke))
- return(false);
- if(!m_button1.ColorBorder(clrBlack))
- return(false);
- if(!Add(m_button1))
- return(false);
- m_button1.Locking(true);
- m_button1.BringToTop();
- //--- succeed
- return(true);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void CControlsDialog::OnClickButton(void)
- {
- if(m_button.Pressed())
- {
- Print(" Clicked on Button");
- m_button.Pressed(false);
- placeSellTrade();
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void CControlsDialog::OnClickButton1(void)
- {
- if(m_button1.Pressed())
- {
- Print(" Clicked on Button 1");
- m_button1.Pressed(false);
- placeBuyTrade();
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool CControlsDialog::CreatePanel(void)
- {
- //--- coordinates
- int x1=0;
- int y1=0;
- int x2=dashWidth;
- int y2=dashHeight;
- //--- create
- if(!backgroundPanel.Create(0,ExtDialog.Name()+"backPanel",m_subwin,x1,y1,x2,y2))
- return(false);
- if(!backgroundPanel.ColorBackground(clrWhiteSmoke))
- return(false);
- if(!backgroundPanel.ColorBorder(00128))
- return(false);
- if(!ExtDialog.Add(backgroundPanel))
- return(false);
- ExtDialog.Minimized(false);
-
-
- backgroundPanel.Alignment(WND_ALIGN_CLIENT,0,0,0,0);
- //--- succeed
- return(true);
- }
-
- CControlsDialog ExtDialog;
- CPanel backgroundPanel;
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
-
- //+------------------------------------------------------------------+
|