LiveSignals

Download script
Profit factor:
0.00

This script serves as an automated trade executor designed to manage positions based on a pre-defined data set. Rather than using complex mathematical indicators or real-time analysis, the logic relies entirely on an external "signals" file to dictate exactly when to enter and exit trades.

Core Functionality

Data Retrieval The system begins by opening and reading a specific spreadsheet-style file (CSV). It scans this file line by line, extracting key pieces of information for each trade, including:

  • A unique identification number (Magic Number).
  • Specific dates and times for both opening and closing the trade.
  • Price levels for entry, profit targets, and stop-loss limits.
  • The specific currency pair (Symbol) and whether the trade should be a "Buy" or "Sell."

Execution Logic The script continuously monitors the current market time against the data provided in the file:

  1. Trade Entry: When the market clock matches the specific opening date and time listed in the file, the script checks if a position is already open. If it finds no active trade for that specific signal, it automatically places a "Buy" or "Sell" order using the predefined volume (Lot size) and price parameters.
  2. Trade Management: For every signal in the list, the script verifies whether the corresponding trade is currently active in your account.
  3. Automatic Exit: The script monitors the "closing date" for each trade. Once the market time reaches or exceeds that specific closing time, and if the trade is still open, the script automatically triggers a command to close the position immediately at the current market price.

Order Identification To ensure accuracy, the logic includes a verification system. It doesn't just close any random trade; it specifically looks for the "Magic Number" (a unique ID) and the correct currency pair. This prevents the script from accidentally closing trades you might have opened manually or through other systems.

Summary of Workflow

In simple terms, this script acts as a digital assistant that reads a "to-do list" of trades. It waits for the exact moment specified on your list to execute a trade and then watches the clock to ensure that trade is closed at the exact time you requested, handling all the manual clicking and monitoring automatically.

Orders Execution
It automatically opens orders when conditions are reachedIt Closes Orders by itself Checks for the total of open ordersChecks for the total of closed orders
Miscellaneous
Uses files from the file systemIt reads information from a file
5 Views
0 Downloads
0 Favorites
LiveSignals
/**
  Variables
**/  

double glbOrderProfit;
double glbOrderOpen;
double glbOrderStop;
double glbOrderType;
double glbOrderTicket;
double mOpen, mClose, mStopLoss, mTakeProfit; 
double ask, bid, point;

int mNumber, spread, file;
string mSymbol, mType, opendate, closedate;

datetime date1, date2;  

double Lots = 5;

int init()
{
return(0);
}

int deinit()
{
return(0);
}

int start()
{

   file = FileOpen("signals.csv",FILE_READ|FILE_CSV,',');
   while (!FileIsEnding(file))
     {
  
       mNumber = StrToInteger(FileReadString(file));
       opendate = FileReadString(file);       
       closedate = FileReadString(file);
       mOpen = StrToDouble(FileReadString(file));    
       mClose = StrToDouble(FileReadString(file));       
       mTakeProfit = StrToDouble(FileReadString(file));
       mStopLoss = StrToDouble(FileReadString(file));
       mType = FileReadString(file);   
       mSymbol = FileReadString(file);   

       date1=StrToTime(opendate);
       date2=StrToTime(closedate);

       ask     = MarketInfo(mSymbol,MODE_ASK);
       bid     = MarketInfo(mSymbol,MODE_BID);   
       spread  = MarketInfo(mSymbol,MODE_SPREAD);   
       point   = MarketInfo(mSymbol,MODE_POINT);

       if (TimeCurrent() == date1) 
       {
         if(mType == "Sell" && OrderFind(mNumber, mSymbol) == false)
         {   
           OrderSend(mSymbol, OP_SELL, Lots, bid, 3, mStopLoss, mTakeProfit, "Sell Order", mNumber, 0, Blue);
         }
         if(mType == "Buy" && OrderFind(mNumber, mSymbol) == false)
         {
           OrderSend(mSymbol, OP_BUY, Lots, ask, 3, mStopLoss, mTakeProfit, "Buy Order", mNumber, 0, Blue);
         }
       }
       
       else if (TimeCurrent() >= date2 && OrderFind(mNumber, mSymbol) == true) 
       {
           CloseOrder(glbOrderTicket);
       }
       
       else 
       {
         continue;
       }  
                
       Print("Magic=", mNumber, ",Symbol=", mSymbol, ",Type=", mType, ",Open=", mOpen, ",Close=", mClose, ",SL=", mStopLoss, ",TakeProfit=", mTakeProfit);   
         
       
      }
   
   FileClose(file);  
   return(0);
}
 

/**
  Close Order Function
**/  

void CloseOrder( int Ticket )
{

  OrderSelect(Ticket, SELECT_BY_TICKET);

  if (OrderType() == OP_BUY) {
    OrderClose(Ticket, OrderLots(), Bid, 0);     
  }  

  else {
    OrderClose(Ticket, OrderLots(), Ask, 0);      
  }  

 return;  

}   
 
/**
  Order Find Function
**/  

bool OrderFind(int Magic, string symbol) 
{

   glbOrderType = -1;
   glbOrderTicket = -1;
   glbOrderProfit = 0;
   glbOrderOpen = -1;
   glbOrderStop = -1;

   int total = OrdersTotal();

   bool res = false;

   for(int cnt = 0 ; cnt < total ; cnt++)

     {

       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

       if(OrderMagicNumber() == Magic && OrderSymbol() == symbol)

         {

           glbOrderType = OrderType();
           glbOrderTicket = OrderTicket();
           glbOrderProfit = OrderProfit();
           glbOrderOpen = OrderOpenPrice();
           glbOrderStop = OrderStopLoss();

           res = true;

         }

     }

 return(res);

}
 

/**
  Scan History
**/  

bool InHistory(int Magic) 
{
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     
     if(OrderMagicNumber() == Magic) {
        return(TRUE);
        break;
     }
     
    }
}
 

Comments