The 4 steps of automated hedging discussed and
the idea of an Algos-R-US startup gets mentioned.
The 4 steps of automated hedging discussed and
the idea of an Algos-R-US startup gets mentioned.
The first part introduces the momentum trading and gives you a trade that is beyond probable.

One correction, I was meant to say, Mr. Maroon was an 828 moving average from the 5-minute world, not the 7.5.
// Ratio Hedger by Macdulio for Automated Trading
#include <stdlib.mqh>
extern int magic_number = 51;
extern int magic_number2 = 52;
extern double Ratio = .8;
extern double MarginCallPercentage = 100;
#property copyright “by Macdulio in 2018”
#property link “https://forexfore.blog”
#property description “Ratio Hedger”
#property description “Clicks on half a hedge upon the Equity/Balance ”
#property description “Ratio dropping below the set value (at market)”
#property description “and another half 10% lower(at market)”
#property description “1/2 hedge also triggered by 150% of the set”
#property description “margin call level (by your broker)”
int profits;
double nakedshorts[];
double nakedlongs[];
double open_price;
double stop_loss_price;
double take_profit_price;
double OrderOpenPrice;
double OrderProfit;
string symbol = Symbol();
int init() {
return(0);
}
int deinit() {
return(0);
}
int start() {
int i, counter;
int counted_bars=IndicatorCounted();
int longcount, shortcount;
double nlongs;
double nshorts;
double longaveragebuffer;
double shortaveragebuffer;
int order_type;
profits = 0;
int hstTotal=OrdersHistoryTotal();
counter = 0;
for(i=OrdersTotal()-1; i>=0 ; i–)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
{
Print(“Access to orders list failed with error (“,GetLastError(),”)”);
break;
}
// if ( Symbol()==”EURUSD” && OrderStopLoss()==0 ) {
if (OrderType() == OP_BUY)
{
nlongs = nlongs+OrderLots();
longcount = longcount+1;
longaveragebuffer = longaveragebuffer+(OrderOpenPrice()*OrderLots());
}
if (OrderType() == OP_SELL )
{
nshorts = nshorts+OrderLots();
shortcount = shortcount+1;
shortaveragebuffer = shortaveragebuffer+(OrderOpenPrice()*OrderLots());
}
// }
}
double comparison = AccountEquity()/AccountBalance();
// Half Hedge for shorts
if (nlongs<nshorts && (comparison<Ratio || AccountMargin()<MarginCallPercentage*1.5) ) {
open_price = open_price = NormalizeDouble(Ask, Digits);
stop_loss_price = NormalizeDouble(0,Digits);
take_profit_price = NormalizeDouble(0,Digits);
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number) {
order_type = OrderType();
if (order_type == ORDER_TYPE_BUY) {
if ((NormalizeDouble(OrderOpenPrice(), Digits) != open_price) || (NormalizeDouble(OrderStopLoss(), Digits) != stop_loss_price) || (NormalizeDouble(OrderTakeProfit(), Digits) != take_profit_price)) {
if (!OrderModify(OrderTicket(), open_price, stop_loss_price, take_profit_price, OrderExpiration()))
Print(“Error: “, ErrorDescription(_LastError));
}
break;
}
else if (order_type == ORDER_TYPE_BUY)
break;
}
if (i < 0)
if (OrderSend(symbol, OP_BUY, NormalizeDouble((nshorts-nlongs)/2,2), open_price, 3, stop_loss_price, take_profit_price, “RATIO HEDGER HALF BUY 0/0”, magic_number) < 0)
Print(“Error: “, ErrorDescription(_LastError));
}
else
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number )
if (OrderType() == ORDER_TYPE_BUY_STOP)
if (!OrderDelete(OrderTicket()))
Print(“Error: “, ErrorDescription(_LastError));
// Full Hedge for shorts
if (nlongs<nshorts && comparison<Ratio-.1 ) {
open_price = open_price = NormalizeDouble(Ask, Digits);
stop_loss_price = NormalizeDouble(0,Digits);
take_profit_price = NormalizeDouble(0,Digits);
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number2) {
order_type = OrderType();
if (order_type == ORDER_TYPE_BUY) {
if ((NormalizeDouble(OrderOpenPrice(), Digits) != open_price) || (NormalizeDouble(OrderStopLoss(), Digits) != stop_loss_price) || (NormalizeDouble(OrderTakeProfit(), Digits) != take_profit_price)) {
if (!OrderModify(OrderTicket(), open_price, stop_loss_price, take_profit_price, OrderExpiration()))
Print(“Error: “, ErrorDescription(_LastError));
}
break;
}
else if (order_type == ORDER_TYPE_BUY)
break;
}
if (i < 0)
if (OrderSend(symbol, OP_BUY, NormalizeDouble(nshorts-nlongs,2), open_price, 3, stop_loss_price, take_profit_price, “RATIO HEDGER BUY 0/0”, magic_number2) < 0)
Print(“Error: “, ErrorDescription(_LastError));
}
else
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number2 )
if (OrderType() == ORDER_TYPE_BUY_STOP)
if (!OrderDelete(OrderTicket()))
Print(“Error: “, ErrorDescription(_LastError));
// Half Hedge For Longs
if (nshorts<nlongs && (comparison<Ratio || AccountMargin()<MarginCallPercentage*1.5)) {
open_price = NormalizeDouble(Bid, Digits);
stop_loss_price = NormalizeDouble(0,Digits);
take_profit_price = NormalizeDouble(0,Digits);
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number) {
order_type = OrderType();
if (order_type == ORDER_TYPE_SELL) {
if ((NormalizeDouble(OrderOpenPrice(), Digits) != open_price) || (NormalizeDouble(OrderStopLoss(), Digits) != stop_loss_price) || (NormalizeDouble(OrderTakeProfit(), Digits) != take_profit_price)) {
if (!OrderModify(OrderTicket(), open_price, stop_loss_price, take_profit_price, OrderExpiration()))
Print(“Error: “, ErrorDescription(_LastError));
}
break;
}
else if (order_type == ORDER_TYPE_SELL)
break;
}
if (i < 0)
if (OrderSend(symbol, OP_SELL, NormalizeDouble((nlongs-nshorts)/2,2), open_price, 3, stop_loss_price, take_profit_price, “RATIO HEDGER HALF SELL 0/0”, magic_number) < 0)
Print(“Error: “, ErrorDescription(_LastError));
}
else
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number)
if (OrderType() == ORDER_TYPE_SELL_STOP)
if (!OrderDelete(OrderTicket()))
Print(“Error: “, ErrorDescription(_LastError));
// Full Hedge For Longs
if (nshorts<nlongs && comparison<Ratio-.1) {
open_price = NormalizeDouble(Bid, Digits);
stop_loss_price = NormalizeDouble(0,Digits);
take_profit_price = NormalizeDouble(0,Digits);
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number2) {
order_type = OrderType();
if (order_type == ORDER_TYPE_SELL) {
if ((NormalizeDouble(OrderOpenPrice(), Digits) != open_price) || (NormalizeDouble(OrderStopLoss(), Digits) != stop_loss_price) || (NormalizeDouble(OrderTakeProfit(), Digits) != take_profit_price)) {
if (!OrderModify(OrderTicket(), open_price, stop_loss_price, take_profit_price, OrderExpiration()))
Print(“Error: “, ErrorDescription(_LastError));
}
break;
}
else if (order_type == ORDER_TYPE_SELL)
break;
}
if (i < 0)
if (OrderSend(symbol, OP_SELL, NormalizeDouble(nlongs-nshorts,2), open_price, 3, stop_loss_price, take_profit_price, “RATIO HEDGER SELL 0/0”, magic_number2) < 0)
Print(“Error: “, ErrorDescription(_LastError));
}
else
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number2)
if (OrderType() == ORDER_TYPE_SELL_STOP)
if (!OrderDelete(OrderTicket()))
Print(“Error: “, ErrorDescription(_LastError));
return(0);
}
It’s no secret that I am developing my auto trading routines for one pair only, the EUR/USD.
Low spread (0.22 pips average ) helps, and so does liquidity: it is being kept to predictability by the large number of traders trading it. Just like the S&P, that is always quoted as a “Benchmark”.
I have come to know some of its characteristics, and I am pretty certain of its Fluctuation Size.
God Awesome is now at V1.4, and the release is getting a delay.
I just implemented the “LEMA continuation trade plot” – both for longs and shorts, extended the Buy/Sell strokes out to their expiration size and included a new trade as well.
The Sharpie Quick Trade has the same trigger as the Sharpie Trade Initiator, but while the latter one is posting limit orders betting on a counter move to spring about from 1/3 Fluctuation Size out, the Quick Trade is betting on a hurl in the current direction, to the extent of 1/4 Fluctuation Size. Yes, we’re talking 8 pips, just where the auto trail stop would put out the 1-pip protective stop loss from the open.
While tying off loose ends, one thing I noticed was an amateur mistake I made. Somehow, when I switched away from at market opening, I ended up with the wrong opening price:
open_price = NormalizeDouble(iClose(symbol,30,0)-FSize/2*10*Point, Digits);
the 0 in bold basically guarantee the trade being pushed out as long as the trade opening condition persists. As you can see below, sharpie 91 had its buy level crossed, yet there was no fill, because of the bad calculation. Copy and paste can close problems at times.
The 0, that was supposed to be 1, pushed the limit order to 1.15725 instead of 1.1579 and so it never got filled. Close[0] is simply the current price.

The second mistake I had to address today, was about the Sharpie Quick trade, that has the “X” plot boxes – showing the trigger level and 0-2 candles out you would see their minimum target.
The current trade, that is about to be stopped out, was opened too late. As a response, I had to decrease the expiration value from 9000 seconds – which was 5 candles out to 3 candles away:
int ClosePendingInSeconds = 5400;
And yes, on the above snapshot you can see the PSAR trader waiting for the ball with an overwhelming volume size. It is a projected 4H PSAR reading that becomes active upon long time no see. 1.1624 – is the rounded short value.
The Reversion To Mean plot is not very encouraging to shorts, and the so the BRGR EA routine (Break/Return Green River) should have opened a long at the strike out, at market, and it didn’t. Another screen plot / EA syncing error I need to look into.
Welcome to a normal day in automated trading.
P.S.: the broker this account is with isn’t listed by Forex Factory, so I sent them a mail.
Later…
PSAR Trader’s order expired, Breakout buyer is lining up for a possible go.

As for BRGR – it seems like I included a filter – due some back testing presumably –
MathAbs(iHi-Close[0])>FMax*10*Point
that is either unnecessary, or does not have the distance right; it certainly prevented a long open that would be making money already, so I commented it out.
First you need to notice a feature that seems to repeat itself.

The feature I found today was a sell signal.
Once you had 3 closes below a LEMA – and price was residing on the other side earlier -, you would start looking at a short sell starting 4 bars out. The short entry level is given: the low of the LEMA, and your stop can be put at the top of the LEMA.
So let’s make a screen plot for the sell condition – and include it in the God Awesome indicator – of course!

(Oranged out for the sell level.)
//expiration 16 hours out
int ClosePendingInSeconds = 57600;
// You’ll need considerate sizing – meaning based on current equity size
extern double AF = 0.35;
for(i=OrdersTotal()-1; i>=0 ; i–)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
{
Print(“Access to orders list failed with error (“,GetLastError(),”)”);
break;
}
if (OrderType() == OP_BUY)
{
nlongs = nlongs+OrderLots();
longcount = longcount+1;
longaveragebuffer = longaveragebuffer+(OrderOpenPrice()*OrderLots());
}
if (OrderType() == OP_SELL )
{
nshorts = nshorts+OrderLots();
shortcount = shortcount+1;
shortaveragebuffer = shortaveragebuffer+(OrderOpenPrice()*OrderLots());
}
}
double equity=NormalizeDouble(AccountEquity()/1000*.9*AF,2);
double currentsize;
if (nlongs>nshorts) currentsize=nlongs;
else currentsize=nshorts;
double difference = equity-currentsize;
//Target distance calculation based on 3-period daily average true range (plus 30%)
//I used simple math to save on run time by avoiding a cycle
double ATRAVG=((iATR(NULL,1440,14,1)+iATR(NULL,1440,14,2)+iATR(NULL,1440,14,3))/3*1.3);
string symbol = Symbol();
int LEMA=414;
// Sell
if ( iClose(symbol,30,1)<iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_LOW,1) &&
iClose(symbol,30,5)<iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_CLOSE,5) &&
iClose(symbol,30,6)<iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_CLOSE,6) &&
iClose(symbol,30,7)<iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_CLOSE,7) &&
iClose(symbol,30,20)>iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,20) &&
iClose(symbol,30,21)>iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,21) &&
iClose(symbol,30,22)>iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,22)
)
{
open_price = NormalizeDouble(iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_LOW,1), Digits);
stop_loss_price = NormalizeDouble(iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,1)+(iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,1)-iMA(symbol,30,LEMA,0,MODE_EMA, PRICE_HIGH,1)), Digits);
take_profit_price = NormalizeDouble(open_price – ATRAVG , Digits);
for (i = OrdersTotal() – 1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number) {
order_type = OrderType();
if (order_type == ORDER_TYPE_SELL_LIMIT) {
if ((NormalizeDouble(OrderOpenPrice(), Digits) != open_price) || (NormalizeDouble(OrderStopLoss(), Digits) != stop_loss_price) || (NormalizeDouble(OrderTakeProfit(), Digits) != take_profit_price)) {
// if (!OrderModify(OrderTicket(), open_price, stop_loss_price, take_profit_price, OrderExpiration()))
Print(“Error: “, ErrorDescription(_LastError));
}
break;
}
else if (order_type == ORDER_TYPE_SELL)
break;
}
if (i < 0)
if (OrderSend(NULL, OP_SELLLIMIT, lots, open_price, 3, stop_loss_price, take_profit_price, magic_number+” LEMA SELL @ RSI “+DoubleToString(iRSI(NULL,0,2,PRICE_MEDIAN,0),2), magic_number,1) < 0)
Print(“Error: “, ErrorDescription(_LastError));
}
else
for (i = OrdersTotal() – 1; i >= 0; i–)
if (TimeCurrent()-OrderOpenTime()>=ClosePendingInSeconds)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magic_number)
if (OrderType() == ORDER_TYPE_SELL_LIMIT)
if (!OrderDelete(OrderTicket()))
Print(“Error: “, ErrorDescription(_LastError));
That’s about 80% of what you will need.
The next step is to download and plug in the historical data you would need for the back testing. Additional filters may be needed of course. That is what back testing is for.
Cheerio,

Fulliautomatix

Automated trading comes with filters. I can show you a couple with today’s 3 trades.

I know, these are 2 trades. There was a 3rd one that did not happen. One by one then.

I could not resist cutting the trade again.
What was I thinking? That the Green River is nearby, and it would dip lower and my Green River buyer routine should open a buy. It did not dip any more. Overthinking is futile. As soon as the trade was 8 pips positive, the auto trail stop would had turned it into a free trade by putting the stop loss one pip above the open.
I am the weakest link in the system, that is not only self sustaining but emotionless and much more efficient in every single way. Of course, I am still in this somehow. I figured out what needed to be done, I picked the filters, and none of the system would exist without me. I am the Alpha, and my system is the Omega.
…maybe I would make one change after all to the stop loss…

I should… perhaps… put back the trail stop value to 1/2 the Fluctuation Size.

My Anchorage Wild trading routine is based on an RSI 2 divergence (not stochastic) + displacement. Here’s 5-months back test.