Hi.
I have background in Java and C but I was never good at cleaning codes and I want to be a junior software engineer even though I am 43. Anyone is kind enough to help me clean the code or I am better of at stackoverflow?
Regards
David.
This is a script on buying whole number or half number for currency pairs that have 3 decimals, 5 decimals or 2 decimals.
It is based off wicksdon'tlie momentum strategy only for breakout that follow one of Einstein laws of inertia.
//+------------------------------------------------------------------+
//| BuyStop105.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
double newopen;
double _50Pips;
double buffer_entry;
double buffer_exit;
// We define the basic data.
double StopLoss=50; // Stop-Loss in pips 3 digits because of decimals
double TakeProfit=130; // Take-Profit in pips. 3 digits because decimals.
double LotSize=0.01; // Lot size in lots
double Slippage=5; // Slippage in pips
double Command=OP_BUYSTOP; // Type of order, BUY
int MagicNumber=16384;
double CalculateNormalizedDigits()
{
if(Digits<=3){
return(0.01);
}
else if(Digits>=4){
return(0.0001);
}
else return(0);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
// for currency pairs that has 3 decimals place
if (Digits ==2)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 1) /1;
_50Pips = newopen - 0.0005;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.5) + " SL is " + newopen);
buffer_entry = newopen+0.5;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
// for currency pairs that has 5 decimals place
if (Digits ==5)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 1000) /1000;
_50Pips = newopen - 0.0005;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.0005) + " SL is " + newopen);
buffer_entry = newopen+0.0005;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
// for currency pairs that has 3 decimals place
if (Digits == 3)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 10) /10;
_50Pips = newopen - 0.05;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.05) + " SL is " + newopen);
buffer_entry = newopen+0.05;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
//--- get minimum stop level
double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
Print("Minimum Stop Level=",minstoplevel," points");
double price=buffer_entry;
//--- calculated SL and TP prices
double stoploss=buffer_entry - StopLoss*Point;
double takeprofit=buffer_entry + TakeProfit*Point;
//--- place market order to buy 1 lot
int ticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize,buffer_entry,Slippage,stoploss,takeprofit,"My order",MagicNumber,0,clrGreen);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
//---
}
//+------------------------------------------------------------------+
I have background in Java and C but I was never good at cleaning codes and I want to be a junior software engineer even though I am 43. Anyone is kind enough to help me clean the code or I am better of at stackoverflow?
Regards
David.
This is a script on buying whole number or half number for currency pairs that have 3 decimals, 5 decimals or 2 decimals.
It is based off wicksdon'tlie momentum strategy only for breakout that follow one of Einstein laws of inertia.
//+------------------------------------------------------------------+
//| BuyStop105.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
double newopen;
double _50Pips;
double buffer_entry;
double buffer_exit;
// We define the basic data.
double StopLoss=50; // Stop-Loss in pips 3 digits because of decimals
double TakeProfit=130; // Take-Profit in pips. 3 digits because decimals.
double LotSize=0.01; // Lot size in lots
double Slippage=5; // Slippage in pips
double Command=OP_BUYSTOP; // Type of order, BUY
int MagicNumber=16384;
double CalculateNormalizedDigits()
{
if(Digits<=3){
return(0.01);
}
else if(Digits>=4){
return(0.0001);
}
else return(0);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
// for currency pairs that has 3 decimals place
if (Digits ==2)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 1) /1;
_50Pips = newopen - 0.0005;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.5) + " SL is " + newopen);
buffer_entry = newopen+0.5;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
// for currency pairs that has 5 decimals place
if (Digits ==5)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 1000) /1000;
_50Pips = newopen - 0.0005;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.0005) + " SL is " + newopen);
buffer_entry = newopen+0.0005;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
// for currency pairs that has 3 decimals place
if (Digits == 3)
{
//--- this formula round of to decimal place. 1000 = 0.001 while 100 = 0.01 and 10 = 0.1
newopen = MathRound(High[0] * 10) /10;
_50Pips = newopen - 0.05;
if (High[0] > newopen)
{
Alert("High is " + High[0] + " Entry price should be " + (newopen+0.05) + " SL is " + newopen);
buffer_entry = newopen+0.05;
buffer_exit = newopen;
}
if (High[0] <= newopen)
{
Alert("High is " + High[0] + " Entry price should be " + newopen + " SL is " + _50Pips);
buffer_entry = newopen;
buffer_exit = _50Pips;
}
}
//--- get minimum stop level
double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
Print("Minimum Stop Level=",minstoplevel," points");
double price=buffer_entry;
//--- calculated SL and TP prices
double stoploss=buffer_entry - StopLoss*Point;
double takeprofit=buffer_entry + TakeProfit*Point;
//--- place market order to buy 1 lot
int ticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize,buffer_entry,Slippage,stoploss,takeprofit,"My order",MagicNumber,0,clrGreen);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
//---
}
//+------------------------------------------------------------------+
You're going to pay a price for every bloody thing you do and don't do