Skip to content

Instantly share code, notes, and snippets.

@tayyebi
Created March 3, 2022 09:07
Show Gist options
  • Save tayyebi/ea0d3ba15627d6b5d248b7932877a725 to your computer and use it in GitHub Desktop.
Save tayyebi/ea0d3ba15627d6b5d248b7932877a725 to your computer and use it in GitHub Desktop.
#property copyright "Tayyebi"
#property link "https://tradingview.com/u/tayyebi"
#property version "1.00"
int OnInit()
{
Comment("Started " + Symbol());
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
ENUM_TIMEFRAMES period = PERIOD_M1;
// Indicators
double bb = iBands(NULL,period,20,2,0,PRICE_LOW);//,MODE_LOWER,0);
double sma = iMA(NULL,period,21,0,MODE_SMA,PRICE_MEDIAN);
double ema = iMA(NULL,period,20,0,MODE_EMA,PRICE_MEDIAN);
// Prices
double high0 = iHigh(NULL, period, 0);
double low0 = iLow(NULL, period, 0);
double up0 = iHigh(NULL, period, 0);
double close1 = iClose(NULL, period, 1);
// Logic
// bool buyCondition = ( low0 >= close1 ) && ( ema <= sma) ;
bool buyCondition = ( low0 > close1) ;
// bool sellCondition = (low0 < up0) && (close1 > up0) && (ema >= sma) ;
bool sellCondition = ( up0 < close1) ;
Comment(StringFormat("high, low, up, close: %d, %d, %d, %d", high0, low0, up0, close1));
// Operations
if ( buyCondition )
{
ObjectCreate(NULL,"signal",OBJ_ARROW_BUY,0,TimeCurrent(), low0);
}
else if (sellCondition)
{
ObjectCreate(NULL,"signal",OBJ_ARROW_SELL,0,TimeCurrent(), high0);
}
// Clear chart
if (!buyCondition && !sellCondition) {
ObjectDelete(NULL, "signal");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment