• Overview
  • Reviews
  • Comments (1)

SFE Library

This library will implement some functions of support used by the SFE EA, which can be useful to other developers.

At this moment, the functions shared in this library, are for tracking the conditions of the opening of the trades, to estimate the difference in the performance between different brokers and estimate if the conditions used in the backtest, are close to the reality.

The library implements funtions for managing different kinds of orders: Market, Stop and Limit orders.

When the functions are used, a file with the information is stored in Files\SFE_Track_Orders. The most important data inside this file is the spread and slippage data. Market orders can have spread and slippage at the same time. In the Stop and Limit orders, only the slippage is computed.

An example of usage is added in the first post on the comments page of this product. The steps for using these functions are:

// ------------------------------------------------- SFE-TRACK-ORDERS(1) DECLARATION BLOCK
class SFE_Track_Orders_Base
{
public:
virtual void add_order(int ticket){};
virtual void pending_order_openprice_modified(int ticket){};
virtual void track_orders(){};
};
#import "..\\Scripts\\Market\\SFE_Utils.ex4"
SFE_Track_Orders_Base *createTrackOrders(string filename, int userID, bool step_minute=true);
#import

SFE_Track_Orders_Base *sfe_track=NULL;
// ------------------------------------------------- SFE-TRACK-ORDERS(1) DECLARATION BLOCK

Creation and destruction of the track entity (step_minute=true means that the general tracking process will be launched only once every minute, to save resources)

int OnInit()
{
// ------------------------------------------------- SFE-TRACK-ORDERS(2) creation of the control entity
sfe_track=createTrackOrders(_filename,_userID,_step_minute);

return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
// ------------------------------------------------- SFE-TRACK-ORDERS(7) delete of the control entity
if (sfe_track!=NULL) {delete sfe_track; sfe_track=NULL;}
}


Track the existing Stop and Limit orders

void OnTick()
{
// ------------------------------------------------- SFE-TRACK-ORDERS(3) tracking of stop/limit kind orders
// the track orders process will find opened stop/limit orders
sfe_track.track_orders();
.......
}

Register the orders when launched

// ------------------------------------------------- SFE-TRACK-ORDERS(4) example of track a market order
   int ticket=OrderSend(NULL,OP_SELL,0.01,Bid,999,Bid+distsl,Bid-disttp,"",MAGIC1);
   if (ticket!=-1)
   {
   sfe_track.add_order(ticket);
   }
// ------------------------------------------------- SFE-TRACK-ORDERS(5) example of track a STOP order
   int ticket=OrderSend(NULL,OP_BUYSTOP,0.01,Ask+distopen,999,Ask+distopen-distsl,Ask+distopen+disttp,"",MAGIC2);
   if (ticket==-1) Print("error ticket: ",ticket," ",GetLastError());
   if (ticket!=-1)
   {
   sfe_track.add_order(ticket);
   }
// ------------------------------------------------- SFE-TRACK-ORDERS(6) example of track a LIMIT order
   int ticket=OrderSend(NULL,OP_BUYLIMIT,0.01,Ask-distopen,999,Ask-distopen-distsl,Ask-distopen+disttp,"",MAGIC3);
   if (ticket==-1) Print("error ticket: ",ticket," ",GetLastError());
   if (ticket!=-1)
   {
   sfe_track.add_order(ticket);
   }
In the attached images, we can see the information stored in the text file, and a screen of a sample external application which reads and shows the results of the text file.


No reviews