Lavoro terminato
Specifiche
I am looking to build a grid trade manager per my directions below. The idea is from Proper Bot, which is available in the Codebase as a sample. My desired code is a simpler version.
OK---since we are starting from scratch, here is the minimum. I don't need the volume check, the hours check, or the MA check. It is very simple. I need a grid trade manager that uses an array as described below. You may wonder why I need the 0 condition included.....I plan on expanding this project for additional fee later. Today's fee is for part 1. Part 1: Get the trade grid to function, without an indicator, using a manual switch, with a close all in FIFO order for the 0 condition.
input int BUYSELLSWITCH=1; // this is just a temporary manual switch. We will replace it later for the indicator. 1 means BUY, -1 means SELL. 0 means close all open orders per FIFO and monitor for new signal. When testing, this would be set to 1 and the EA would start Buying right away. When set to -1 it would start selling right away. When set to 0, it would close all open orders right away and then do nothing as it waits for the variable to change. To test the 0 condition, manually open several trades before starting the EA.
input double First_Lot= 0.01; // This is the first order that starts the process.
input double BrokerviewTP=600 // TP set in the order for the broker to see. These values are the same for all orders in the system, relative to each order. For safety. They will never be hit, unless my server goes down
input double BrokerViewSL=1000 // SL set in the order for the broker to see. These values are the same for all orders in the system, relative to each order. For safety. They will never be hit, unless my server goes down
input string Grid_Map = "120/0.02/150/300 130/0.03/100/200 140/0.04/50/100 150/0.05/40/90 160/0.06/30/80"; //convert string to array.
The four values for each item provide: points from previous order to add a new order, lot size of new order, TP for ALL open trades relative to the first lot (invisible to broker), SL for ALL open trades relative to the first lot (invisible to broker)
This way, I have full control of the TP and SL points, relative to the First_Lot price, and they change according to the array each time a new order is added. At every tick, the EA needs to check the BUYSELLSWITCH for a 0 condition to close all open trades in FIFO order. When there are no open orders, at every tick, the EA needs to check the BUYSELLSWITCH for a 1 or -1 condition to open the First_Lot.
input int BrokerviewTP=600;
input int BrokerViewSL=1000;
input int Slippage = 30;
input double First_Lot= 0.01;
input double First_Lot_TP points=200
input double First_Lot_SL points=400
input string Grid_Map = "120/0.02/150/300 130/0.03/100/200 140/0.04/50/100 150/0.05/40/90 160/0.06/30/80";
ALL close prices would be calculated relative to the original First_Lot_order_price, and readjusted according to the array.
Example: Ea opens a Buy order of 0.01 Lots at 1.1800. The order is set to TP at 300 points and SL at 1200 points (broker visible).
The Ea will set close_profit_price = First_Lot_order_price + 200. Ea will set close_loss_price = First_Lot_order_price - 400
Then if price moves down 120 points, EA will open the next 0.02 order, and set close_profit_price = First_Lot_order_price + 150. Ea will set close_loss_price = First_Lot_order_price - 300
Then if price moves down 130 points, EA will open the next 0.03 order, and set close_profit_price = First_Lot_order_price + 100. Ea will set close_loss_price = First_Lot_order_price - 200
Then if price moves down 140 points, EA will open the next 0.04 order, and set close_profit_price = First_Lot_order_price + 50. Ea will set close_loss_price = First_Lot_order_price - 100
Then if price moves down 150 points, EA will open the next 0.05 order, and set close_profit_price = First_Lot_order_price + 40. Ea will set close_loss_price = First_Lot_order_price - 90
Then if price moves down 160 points, EA will open the next 0.06 order, and set close_profit_price = First_Lot_order_price + 30. Ea will set close_loss_price = First_Lot_order_price - 80
These would all be invisible to the broker, because all he will ever see is the Take_Profit and Stop_Loss marks on each trade which will only get hit if EA is shut down due to power failure, or setting grid values higher than the broker visible SL and TP (which would be a user error, not an EA mistake)
How much will you charge me for this much work?
In part 2, which I will pay for separately, we will replace the BUYSELLSWITCH with an external indicator. This way, I can use this EA to run from any kind of indicator I choose.
Here is the sample code of this portion from the ProperBot (it is only 2 levels in the array, though...we need 4)
void init()
{
gi_Slippage=Slippage;
gs_Symbol=_Symbol;
// Points to prices:
gd_One_Pip_Ratio=MathPow(10,Digits);
gd_TP = Take_Profit / gd_One_Pip_Ratio;
gd_SL = Stop_Loss / gd_One_Pip_Ratio;
gd_Stop_Level=MarketInfo(gs_Symbol,MODE_STOPLEVEL)/gd_One_Pip_Ratio;
// Strings to double:
string sa_Grid_Levels[];
double da_Grid_Level[2]; //Would you change this to a 4?????
String_To_Array(Grid_Map,sa_Grid_Levels," ");
int i_Grid_Level=ArraySize(sa_Grid_Levels);
ArrayResize(gd_Distances_Map,i_Grid_Level);
ArrayResize(gd_Lots_Map,i_Grid_Level);
gi_Last_Index=i_Grid_Level-1;
while(i_Grid_Level>0)
{
i_Grid_Level--;
String_To_Double_Array(sa_Grid_Levels[i_Grid_Level],da_Grid_Level,"/");
gd_Distances_Map[i_Grid_Level]=da_Grid_Level[0]/gd_One_Pip_Ratio;
gd_Lots_Map[i_Grid_Level]=da_Grid_Level[1];
Print(i_Grid_Level, ": ", gd_Distances_Map[i_Grid_Level], " / ", gd_Lots_Map[i_Grid_Level]);
}
gi_Connect_Wait*=1000;
gi_Second_From=3600*Start_Hour+60*Start_Minute;
gi_Second_To=3600*Finish_Hour+60*Finish_Minute;
}