//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2020, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property service #include "PositionInfo.mqh" CPositionInfo position; #include "TradeAlt.mqh" CTradeAlt trade; input double iEquityStop = 500; // Profit Target (Percent of Start Lot) input double iStartLots = 0.01; // Trade Lot //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { while(!IsStopped()) { double yet2close = GlobalVariableGet("Yet2Close"); if(!GlobalVariableCheck("Yet2Close") || GlobalVariableGet("Yet2Close")<2 || GlobalVariableGet("Yet2Close")>3) GlobalVariableSet("Yet2Close",yet2close); if(yet2close!=2) // 2 == continue and close ALL trades return; static double eqplus = iEquityStop*iStartLots*10; int total = PositionsTotal(); if(total<1) { yet2close = 3; GlobalVariableSet("Yet2Close",yet2close); if(!GlobalVariableCheck("MaxEqu") || GlobalVariableGet("MaxEqu")<=0.0) GlobalVariableSet("MaxEqu",AccountInfoDouble(ACCOUNT_BALANCE)+eqplus); Sleep(5000); return; } for(int k=total-1; k>=0; k--) { if(position.SelectByIndex(k)) { if(PositionGetTicket(k)<=0 || PositionGetTicket(k)!=position.Ticket()) break; trade.PositionClose(position.Ticket(),3); } } Sleep(5000); } } //+------------------------------------------------------------------+In the eas, which are on multiple charts, and different symbols, I have told them to sleep 1 second if the gv is 2. 2 means that the service is already been told to close all trades.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
gidday.
This is my first attempt at creating a service. The plan was to make this into an ea that would close all trades when other eas changed a globalvariable. But I had been reading up on services, so I thought i'd have a crack at doing a service; altho I am unsure if a service or an ea is better for this task. Anyways -- when this gv called "Yet2Close" is made into a 2 (double type); this service would close all trades, and then change this gv to 3.
The issue I have is that when i have it under service folder, it shows the red square, even after i right click on it and click start. And when I have it under expert folder, it has the play icon, but says stopped. Is it working or isnt it? See below it is in expert folder, showing the play button, but also says stopped.
Is it working or not?