//+------------------------------------------------------------------+
//| StratosZephyr.mq5 |
//| Generated by DeepAI |
//| |
//+------------------------------------------------------------------+
input double TakeProfit = 120; // Take Profit in points
input double LotSize = 0.01; // Lot size
input bool Autolot = false; // Auto lot management
input double Risk = 3.0; // Risk percentage
input double StopLoss = 50; // Stop Loss in points
input int MagicNumber = 937843; // Magic Number
input double LossCapAmount = 1000; // Maximum loss cap amount
input bool ScaleLossCapWithLotSize = true; // Scale loss cap with lot size
input int SpreadAllowed = 300; // Allowed Spread
input bool EnableConcurrentBuyingAndSelling = true; // Allow concurrent orders
input int RSI_Period = 14; // RSI period
input double Overbought_Level = 70.0; // Overbought level for RSI
input double Oversold_Level = 30.0; // Oversold level for RSI
input int TradingWindowOpenHour = 22; // Trading opens at hour
input int TradingWindowCloseHour = 8; // Trading closes at hour
input bool TradeOnMonday = true; // Trade on Monday
input bool TradeOnTuesday = true; // Trade on Tuesday
input bool TradeOnWednesday = true; // Trade on Wednesday
input bool TradeOnThursday = true; // Trade on Thursday
input bool TradeOnFriday = true; // Trade on Friday
input bool TradeOnSaturday = false; // Trade on Saturday
input bool TradeOnSunday = false; // Trade on Sunday
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Check if trading is allowed
if (!IsTradingAllowed())
{
return; // Exit if trading is not allowed
}
double rsiValue = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE);
// Buy condition
if (rsiValue < Oversold_Level && PermitBuyOrders())
{
PlaceOrder(TRADE_ACTION_BUY); // Call place order for buy
}
// Sell condition
if (rsiValue > Overbought_Level && PermitSellOrders())
{
PlaceOrder(TRADE_ACTION_SELL); // Call place order for sell
}
}
//+------------------------------------------------------------------+
//| Place order function |
//+------------------------------------------------------------------+
void PlaceOrder(int orderType)
{
MqlTradeRequest request; // For sending a trading request
MqlTradeResult result; // To hold the trading result
// Check that orderType is valid
if (orderType != TRADE_ACTION_BUY && orderType != TRADE_ACTION_SELL)
{
Print("Invalid order type: ", orderType);
return; // Exit if order type is invalid
}
// Set up the trade request
request.symbol = Symbol(); // Get the current trading symbol
request.volume = Autolot ? CalculateLotSize() : LotSize; // Define the volume
// Cast orderType to the appropriate enum type if needed
request.action = (TRADE_ACTION)orderType;
// Calculate Take Profit and Stop Loss
request.tp = (orderType == TRADE_ACTION_BUY) ? NormalizeDouble(Ask + (TakeProfit * _Point), _Digits)
: NormalizeDouble(Bid - (TakeProfit * _Point), _Digits);
request.sl = (orderType == TRADE_ACTION_BUY) ? NormalizeDouble(Ask - (StopLoss * _Point), _Digits)
: NormalizeDouble(Bid + (StopLoss * _Point), _Digits);
request.deviation = SpreadAllowed; // Set allowable slippage
request.magic = MagicNumber; // Set unique identifier for the order
request.comment = "Gold Robot Order"; // Set the order comment
// Send the order
if (!OrderSend(request, result)) // Execute the trade
{
Print("Error sending order: ", GetLastError()); // Print detailed error info
}
else
{
Print("Order sent successfully: ", result.order); // Print success message
}
}
//+------------------------------------------------------------------+
//| Calculate lot size based on risk management |
//+------------------------------------------------------------------+
double CalculateLotSize()
{
double accountRisk = AccountBalance() * (Risk / 100);
double lotSize = accountRisk / (StopLoss * _Point);
return NormalizeDouble(lotSize, 2);
}
//+------------------------------------------------------------------+
//| Function to check if trading is allowed |
//+------------------------------------------------------------------+
bool IsTradingAllowed()
{
datetime now = TimeCurrent(); // Get the current time
int hour = TimeHour(now); // Get the current hour
int dayOfWeek = TimeDayOfWeek(now); // Get the current day of the week
// Adjust for trading days and hours
if ((dayOfWeek == 0 && !TradeOnSunday) ||
(dayOfWeek == 6 && !TradeOnSaturday) ||
(dayOfWeek == 5 && hour >= TradingWindowCloseHour) ||
(hour < TradingWindowOpenHour) ||
(hour >= TradingWindowCloseHour))
{
return false; // Trading is not allowed
}
return true; // Trading is allowed
}
// Checks permissions for buy orders
bool PermitBuyOrders()
{
return EnableConcurrentBuyingAndSelling;
}
// Checks permissions for sell orders
bool PermitSellOrders()
{
return EnableConcurrentBuyingAndSelling;
}
//+------------------------------------------------------------------+/* package whatever; // don't place package name! */
/*
This source code accompanies the article, "Using The Golay Error Detection And
Correction Code", by Hank Wallace. This program demonstrates use of the Golay
code.
Usage: G DATA Encode/Correct/Verify/Test
where DATA is the data to be encoded, codeword to be corrected,
or codeword to be checked for errors. DATA is hexadecimal.
Examples:
G 555 E encodes information value 555 and prints a codeword
G ABC123 C corrects codeword ABC123
G ABC123 V checks codeword ABC123 for errors
G ABC123 T tests routines, ABC123 is a dummy parameter
This program may be freely incorporated into your programs as needed. It
compiles under Borland's Turbo C 2.0. No warranty of any kind is granted.
*/
#include "stdio.h"
#include "conio.h"
#define POLY 0xAE3 /* or use the other polynomial, 0xC75 */
/* ====================================================== */
unsigned long golay(unsigned long cw)
/* This function calculates [23,12] Golay codewords.
The format of the returned longint is
[checkbits(11),data(12)]. */
{
int i;
unsigned long c;
cw&=0xfffl;
c=cw; /* save original codeword */
for (i=1; i<=12; i++) /* examine each data bit */
{
if (cw & 1) /* test data bit */
cw^=POLY; /* XOR polynomial */
cw>>=1; /* shift intermediate result */
}
return((cw<<12)|c); /* assemble codeword */
}
/* ====================================================== */
int parity(unsigned long cw)
/* This function checks the overall parity of codeword cw.
If parity is even, 0 is returned, else 1. */
{
unsigned char p;
/* XOR the bytes of the codeword */
p=*(unsigned char*)&cw;
p^=*((unsigned char*)&cw+1);
p^=*((unsigned char*)&cw+2);
/* XOR the halves of the intermediate result */
p=p ^ (p>>4);
p=p ^ (p>>2);
p=p ^ (p>>1);
/* return the parity result */
return(p & 1);
}
/* ====================================================== */
unsigned long syndrome(unsigned long cw)
/* This function calculates and returns the syndrome
of a [23,12] Golay codeword. */
{
int i;
cw&=0x7fffffl;
for (i=1; i<=12; i++) /* examine each data bit */
{
if (cw & 1) /* test data bit */
cw^=POLY; /* XOR polynomial */
cw>>=1; /* shift intermediate result */
}
return(cw<<12); /* value pairs with upper bits of cw */
}
/* ====================================================== */
int weight(unsigned long cw)
/* This function calculates the weight of
23 bit codeword cw. */
{
int bits,k;
/* nibble weight table */
const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
bits=0; /* bit counter */
k=0;
/* do all bits, six nibbles max */
while ((k<6) && (cw))
{
bits=bits+wgt[cw & 0xf];
cw>>=4;
k++;
}
return(bits);
}
/* ====================================================== */
unsigned long rotate_left(unsigned long cw, int n)
/* This function rotates 23 bit codeword cw left by n bits. */
{
int i;
if (n != 0)
{
for (i=1; i<=n; i++)
{
if ((cw & 0x400000l) != 0)
cw=(cw << 1) | 1;
else
cw<<=1;
}
}
return(cw & 0x7fffffl);
}
/* ====================================================== */
unsigned long rotate_right(unsigned long cw, int n)
/* This function rotates 23 bit codeword cw right by n bits. */
{
int i;
if (n != 0)
{
for (i=1; i<=n; i++)
{
if ((cw & 1) != 0)
cw=(cw >> 1) | 0x400000l;
else
cw>>=1;
}
}
return(cw & 0x7fffffl);
}
/* ====================================================== */
unsigned long correct(unsigned long cw, int *errs)
/* This function corrects Golay [23,12] codeword cw, returning the
corrected codeword. This function will produce the corrected codeword
for three or fewer errors. It will produce some other valid Golay
codeword for four or more errors, possibly not the intended
one. *errs is set to the number of bit errors corrected. */
{
unsigned char
w; /* current syndrome limit weight, 2 or 3 */
unsigned long
mask; /* mask for bit flipping */
int
i,j; /* index */
unsigned long
s, /* calculated syndrome */
cwsaver; /* saves initial value of cw */
cwsaver=cw; /* save */
*errs=0;
w=3; /* initial syndrome weight threshold */
j=-1; /* -1 = no trial bit flipping on first pass */
mask=1;
while (j<23) /* flip each trial bit */
{
if (j != -1) /* toggle a trial bit */
{
if (j>0) /* restore last trial bit */
{
cw=cwsaver ^ mask;
mask+=mask; /* point to next bit */
}
cw=cwsaver ^ mask; /* flip next trial bit */
w=2; /* lower the threshold while bit diddling */
}
s=syndrome(cw); /* look for errors */
if (s) /* errors exist */
{
for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
{
if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
{
cw=cw ^ s; /* remove errors */
cw=rotate_right(cw,i); /* unrotate data */
return(s=cw);
}
else
{
cw=rotate_left(cw,1); /* rotate to next pattern */
s=syndrome(cw); /* calc new syndrome */
}
}
j++; /* toggle next trial bit */
}
else
return(cw); /* return corrected codeword */
}
return(cwsaver); /* return original if no corrections */
} /* correct */
/* ====================================================== */
int decode(int correct_mode, int *errs, unsigned long *cw)
/* This function decodes codeword *cw in one of two modes. If correct_mode
is nonzero, error correction is attempted, with *errs set to the number of
bits corrected, and returning 0 if no errors exist, or 1 if parity errors
exist. If correct_mode is zero, error detection is performed on *cw,
returning 0 if no errors exist, 1 if an overall parity error exists, and
2 if a codeword error exists. */
{
unsigned long parity_bit;
if (correct_mode) /* correct errors */
{
parity_bit=*cw & 0x800000l; /* save parity bit */
*cw&=~0x800000l; /* remove parity bit for correction */
*cw=correct(*cw, errs); /* correct up to three bits */
*cw|=parity_bit; /* restore parity bit */
/* check for 4 bit errors */
if (parity(*cw)) /* odd parity is an error */
return(1);
return(0); /* no errors */
}
else /* detect errors only */
{
*errs=0;
if (parity(*cw)) /* odd parity is an error */
{
*errs=1;
return(1);
}
if (syndrome(*cw))
{
*errs=1;
return(2);
}
else
return(0); /* no errors */
}
} /* decode */
/* ====================================================== */
void golay_test(void)
/* This function tests the Golay routines for detection and correction
of various patterns of error_limit bit errors. The error_mask cycles
over all possible values, and error_limit selects the maximum number
of induced errors. */
{
unsigned long
error_mask, /* bitwise mask for inducing errors */
trashed_codeword, /* the codeword for trial correction */
virgin_codeword; /* the original codeword without errors */
unsigned char
pass=1, /* assume test passes */
error_limit=3; /* select number of induced bit errors here */
int
error_count; /* receives number of errors corrected */
virgin_codeword=golay(0x555); /* make a test codeword */
if (parity(virgin_codeword))
virgin_codeword^=0x800000l;
for (error_mask=0; error_mask<0x800000l; error_mask++)
{
/* filter the mask for the selected number of bit errors */
if (weight(error_mask) <= error_limit) /* you can make this faster! */
{
trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
if (trashed_codeword ^ virgin_codeword)
{
printf("Unable to correct %d errors induced with error mask = 0x%lX\n", weight(error_mask),error_mask);
pass=0;
}
if (kbhit()) /* look for user input */
{
if (getch() == 27) return; /* escape exits */
/* other key prints status */
printf("Current test count = %ld of %ld\n",error_mask
,0x800000l
); }
}
}
printf("Golay test %s!\n",pass?
"PASSED":"FAILED"); }
/* ====================================================== */
void main(int argument_count, char *argument[])
{
int i,j;
unsigned long l,g;
const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
" where DATA is the data to be encoded, codeword to be corrected,\n"
" or codeword to be checked for errors. DATA is hexadecimal.\n\n"
"Examples:\n\n"
" G 555 E encodes information value 555 and prints a codeword\n"
" G ABC123 C corrects codeword ABC123\n"
" G ABC123 V checks codeword ABC123 for errors\n"
" G ABC123 T tests routines, ABC123 is a dummy parameter\n\n";
if (argument_count != 3)
{
}
if (sscanf(argument
[1],"%lx",&l
) != 1) {
}
switch (toupper(*argument[2]))
{
case 'E': /* encode */
l&=0xfff;
l=golay(l);
if (parity(l)) l^=0x800000l;
break;
case 'V': /* verify */
if (decode(0,&i,&l))
printf("Codeword %lX is not a Golay codeword.\n",l
); else
printf("Codeword %lX is a Golay codeword.\n",l
); break;
case 'C': /* correct */
g=l; /* save initial codeword */
j=decode(1,&i,&l);
if ((j) && (i))
printf("Codeword %lX had %d bits corrected,\n" "resulting in codeword %lX with a parity error.\n",g,i,l);
else
if ((j == 0) && (i))
printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g
,i
,l
); else
if ((j) && (i == 0))
printf("Codeword %lX has a parity error. No bits were corrected.\n",g
); else
if ((j == 0) && (i == 0))
printf("Codeword %lX does not require correction.\n",g
); break;
case 'T': /* test */
printf("Press SPACE for status, ESC to exit test...\n"); golay_test();
break;
default:
}
}
/* end of G.C */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
}
}