Wszystkie pytania dozwolone początkujących programistów
Re: Wszystkie pytania dozwolone początkujących programistów
Paniczki jak zrobic root na szajsungu galaxy ace 3? Podpowiedzcie please
Re: Wszystkie pytania dozwolone początkujących programistów
Witam. Mam następujący problem. Jak zamknąć pozycje otwarte i oczekujące, na TYM konkretnym walorze (pozycje na innych walorach nie mogą zostać zamknięte), przerzucając skrypt na okienko danego waloru? Próbowałem funkcją ChartWindowOnDropped ale warunek który wrzuciłem nie sprawdza nic bo zawsze będzie true, a nie mam żadnego pomysłu jak to inaczej zinterpretować i w którym miejscu. Jakieś podpowiedzi? Póki co skrypt zamyka wszystkie pozycje na całym koncie.
#property strict
void OnStart()
{
exit_order();
}
void exit_order()
{
for(int i = OrdersTotal() - 1; i >= 0 ; i--)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderType()<=1 && ChartWindowOnDropped()==0)
{
OrderClose(OrderTicket(), OrderLots(),OrderClosePrice(),5);
}
else if(OrderType()>1 && ChartWindowOnDropped()==0)
{
OrderDelete(OrderTicket());
}
}
}
#property strict
void OnStart()
{
exit_order();
}
void exit_order()
{
for(int i = OrdersTotal() - 1; i >= 0 ; i--)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderType()<=1 && ChartWindowOnDropped()==0)
{
OrderClose(OrderTicket(), OrderLots(),OrderClosePrice(),5);
}
else if(OrderType()>1 && ChartWindowOnDropped()==0)
{
OrderDelete(OrderTicket());
}
}
}
- ninjaproject
- Maniak
- Posty: 4944
- Rejestracja: 30 lip 2019, 13:15
Re: Wszystkie pytania dozwolone początkujących programistów
Trejder, Mentor/trener, aka. Dadas, fx-technik, obecnie ninjaproject.
Programuję wskaźniki i EA do MetaTrader 4/5.
Programuję wskaźniki i EA do MetaTrader 4/5.
Re: Wszystkie pytania dozwolone początkujących programistów
Może dodaj warunek sprawdzający czy OrderSymbol równa się ChartSymbol()
https://docs.mql4.com/trading/ordersymbol
https://docs.mql4.com/chart_operations/chartsymbol
czyli coś takiego
https://docs.mql4.com/trading/ordersymbol
https://docs.mql4.com/chart_operations/chartsymbol
czyli coś takiego
Kod: Zaznacz cały
#property strict
void OnStart()
{
exit_order();
}
void exit_order()
{
for(int i = OrdersTotal() - 1; i >= 0 ; i--)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderType()<=1 && OrderSymbol() == ChartSymbol(0))
{
OrderClose(OrderTicket(), OrderLots(),OrderClosePrice(),5);
}
else if(OrderType()>1 && OrderSymbol() == ChartSymbol(0))
{
OrderDelete(OrderTicket());
}
}
}
Ostatnio zmieniony 29 sty 2021, 00:42 przez rookie2, łącznie zmieniany 1 raz.
https://www.myfxbook.com/members/rookie_t/pycha-kroczy-przed-upadkiem/7931743
- ninjaproject
- Maniak
- Posty: 4944
- Rejestracja: 30 lip 2019, 13:15
Re: Wszystkie pytania dozwolone początkujących programistów
Kod: Zaznacz cały
//+------------------------------------------------------------------+
int OrdersCloseAll()
{
total = OrdersTotal();
result = false;
for(int cnt=total-1;cnt>=0;cnt--)
{
if(OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES))
ordertype = OrderType();
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic_Number)
{
switch(ordertype)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), Bid, 0, clrNONE );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), Ask, 0, clrNONE );
}
if(result == false)
{
Print("Order " , OrderTicket() , failed to close. Error:" , GetLastError() );
Sleep(3000);
}
else
Print("Order " , OrderTicket() , " closed successfully." );
}
}
return(0);
}
//+------------------------------------------------------------------+
Trejder, Mentor/trener, aka. Dadas, fx-technik, obecnie ninjaproject.
Programuję wskaźniki i EA do MetaTrader 4/5.
Programuję wskaźniki i EA do MetaTrader 4/5.
Re: Wszystkie pytania dozwolone początkujących programistów
Dziękuje serdecznie. Działa
Re: Wszystkie pytania dozwolone początkujących programistów
Technik, jesteś? Może będziesz wiedział Ty co jest nie tak. Jak pobrać ceny z fibo w tym skrypcie. Dokładnie chodzi o linie numer 384 gdzie jest Print( " == > " + i + " --- " + ss[i) . Pobiera mi tylko min i max, czyli poziomy 0 i 100%, a cen pomiędzy już nie. Z kolei OBJPROP_LEVELVALUE, pętla wcześniej, czyli levele w % już pobiera normalnie. Na testerze puść jak coś bo OnCalculate teraz nie działa, bo rynek nie chodzi. Albo ustaw w onInit() timer co sekunde czyli EventSetTimer(1); i wstaw kod z onCalculate to void onTimer(). Ogarniesz. U mnie wywala błąd 4051 , Invalid function parameter value https://docs.mql4.com/constants/errorsw ... errorcodes
Potrzebuje pobrać wszystkie ceny z pozimów fibo. Ilość leweli i jakie są procenty dobrze zapisuje, dobrze zwraca na w argumencie [out] tych funkcji, a tego nie kumam czemu tylko 0 i 100%.
Albo ktoś kto wie o co c'mon.
To jest wskaźnik btw.
Potrzebuje pobrać wszystkie ceny z pozimów fibo. Ilość leweli i jakie są procenty dobrze zapisuje, dobrze zwraca na w argumencie [out] tych funkcji, a tego nie kumam czemu tylko 0 i 100%.
Albo ktoś kto wie o co c'mon.
To jest wskaźnik btw.
Kod: Zaznacz cały
#property strict
//--- description
#property description "Script draws \"Fibonacci Retracement\" graphical object."
#property description "Anchor point coordinates are set in percentage of"
#property description "the chart window size."
//--- display window of the input parameters during the script's launch
//#property script_show_inputs
#property indicator_chart_window
//--- input parameters of the script
input string InpName="FiboLevels"; // Object name
input int InpDate1=10; // 1 st point's date, %
input int InpPrice1=65; // 1 st point's price, %
input int InpDate2=90; // 2 nd point's date, %
input int InpPrice2=85; // 2 nd point's price, %
input color InpColor=clrRed; // Object color
input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Line style
input int InpWidth=1; // Line width
input bool InpBack=false; // Background object
input bool InpSelection=true; // Highlight to move
input bool InpRayRight=false; // Object's continuation to the right
input bool InpHidden=true; // Hidden in the object list
input long InpZOrder=0; // Priority for mouse click
//+------------------------------------------------------------------+
//| Create Fibonacci Retracement by the given coordinates |
//+------------------------------------------------------------------+
bool FiboLevelsCreate(const long chart_ID=0, // chart's ID
const string name="FiboLevels", // object name
const int sub_window=0, // subwindow index
datetime time1=0, // first point time
double price1=0, // first point price
datetime time2=0, // second point time
double price2=0, // second point price
const color clr=clrRed, // object color
const ENUM_LINE_STYLE style=STYLE_SOLID, // object line style
const int width=1, // object line width
const bool back=false, // in the background
const bool selection=true, // highlight to move
const bool ray_right=false, // object's continuation to the right
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- set anchor points' coordinates if they are not set
ChangeFiboLevelsEmptyPoints(time1,price1,time2,price2);
//--- reset the error value
ResetLastError();
//--- Create Fibonacci Retracement by the given coordinates
if(!ObjectCreate(chart_ID,name,OBJ_FIBO,sub_window,time1,price1,time2,price2))
{
Print(__FUNCTION__,
": failed to create \"Fibonacci Retracement\"! Error code = ",GetLastError());
return(false);
}
//--- set color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line style
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of highlighting the channel for moving
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- enable (true) or disable (false) the mode of continuation of the object's display to the right
ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Set number of levels and their parameters |
//+------------------------------------------------------------------+
bool FiboLevelsSet(int levels, // number of level lines
double &values[], // values of level lines
color &colors[], // color of level lines
ENUM_LINE_STYLE &styles[], // style of level lines
int &widths[], // width of level lines
const long chart_ID=0, // chart's ID
const string name="FiboLevels") // object name
{
//--- check array sizes
if(levels!=ArraySize(colors) || levels!=ArraySize(styles) ||
levels!=ArraySize(widths) || levels!=ArraySize(widths))
{
Print(__FUNCTION__,": array length does not correspond to the number of levels, error!");
return(false);
}
//--- set the number of levels
ObjectSetInteger(chart_ID,name,OBJPROP_LEVELS,levels);
//--- set the properties of levels in the loop
for(int i=0;i<levels;i++)
{
//--- level value
ObjectSetDouble(chart_ID,name,OBJPROP_LEVELVALUE,i,values[i]);
//--- level color
ObjectSetInteger(chart_ID,name,OBJPROP_LEVELCOLOR,i,colors[i]);
//--- level style
ObjectSetInteger(chart_ID,name,OBJPROP_LEVELSTYLE,i,styles[i]);
//--- level width
ObjectSetInteger(chart_ID,name,OBJPROP_LEVELWIDTH,i,widths[i]);
//--- level description
ObjectSetString(chart_ID,name,OBJPROP_LEVELTEXT,i,DoubleToString(100*values[i],1));
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Move Fibonacci Retracement anchor point |
//+------------------------------------------------------------------+
bool FiboLevelsPointChange(const long chart_ID=0, // chart's ID
const string name="FiboLevels", // object name
const int point_index=0, // anchor point index
datetime time=0, // anchor point time coordinate
double price=0) // anchor point price coordinate
{
//--- if point position is not set, move it to the current bar having Bid price
if(!time)
time=TimeCurrent();
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
ResetLastError();
//--- move the anchor point
if(!ObjectMove(chart_ID,name,point_index,time,price))
{
Print(__FUNCTION__,
": failed to move the anchor point! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Delete Fibonacci Retracement |
//+------------------------------------------------------------------+
bool FiboLevelsDelete(const long chart_ID=0, // chart's ID
const string name="FiboLevels") // object name
{
//--- reset the error value
ResetLastError();
//--- delete the object
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": failed to delete \"Fibonacci Retracement\"! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Check the values of Fibonacci Retracement anchor points and set |
//| default values for empty ones |
//+------------------------------------------------------------------+
void ChangeFiboLevelsEmptyPoints(datetime &time1,double &price1,
datetime &time2,double &price2)
{
//--- if the second point's time is not set, it will be on the current bar
if(!time2)
time2=TimeCurrent();
//--- if the second point's price is not set, it will have Bid value
if(!price2)
price2=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- if the first point's time is not set, it is located 9 bars left from the second one
if(!time1)
{
//--- array for receiving the open time of the last 10 bars
datetime temp[10];
CopyTime(Symbol(),Period(),time2,10,temp);
//--- set the first point 9 bars left from the second one
time1=temp[0];
}
//--- if the first point's price is not set, move it 200 points below the second one
if(!price1)
price1=price2-200*SymbolInfoDouble(Symbol(),SYMBOL_POINT);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check correctness of the input parameters
if(InpDate1<0 || InpDate1>100 || InpPrice1<0 || InpPrice1>100 ||
InpDate2<0 || InpDate2>100 || InpPrice2<0 || InpPrice2>100)
{
Print("Error! Incorrect values of input parameters!");
return;
}
//--- number of visible bars in the chart window
int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);
//--- price array size
int accuracy=1000;
//--- arrays for storing the date and price values to be used
//--- for setting and changing the coordinates of Fibonacci Retracement anchor points
datetime date[];
double price[];
//--- memory allocation
ArrayResize(date,bars);
ArrayResize(price,accuracy);
//--- fill the array of dates
ResetLastError();
if(CopyTime(Symbol(),Period(),0,bars,date)==-1)
{
Print("Failed to copy time values! Error code = ",GetLastError());
return;
}
//--- fill the array of prices
//--- find the highest and lowest values of the chart
//double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
//double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
int max_shift = 0;
int min_shift = 0;
double max_price = 0;
double min_price = 0;
datetime max_date = 0;
datetime min_date = 0;
int range = 400;
for (int i = Bars; i > 0; i--) {
if (i > range) continue;
max_shift = iHighest(ChartSymbol(), ChartPeriod(), MODE_HIGH, range, i);
min_shift = iLowest(ChartSymbol(), ChartPeriod(), MODE_LOW, range, i);
}
max_price = iHigh(ChartSymbol(), ChartPeriod(), max_shift);
min_price = iLow(ChartSymbol(), ChartPeriod(), min_shift);
max_date = iTime(ChartSymbol(), ChartPeriod(), max_shift);
min_date = iTime(ChartSymbol(), ChartPeriod(), min_shift);
Print(bars);
Print(max_price + " " + min_price);
//--- define a change step of a price and fill the array
double step=(max_price-min_price)/accuracy;
for(int i=0;i<accuracy;i++) {
price[i]=min_price+i*step;
// Print(i + " " +price[i]);
}
//--- define points for drawing Fibonacci Retracement
int d1=InpDate1*(bars-1)/100;
int d2=InpDate2*(bars-1)/100;
int p1=InpPrice1*(accuracy-1)/100;
int p2=InpPrice2*(accuracy-1)/100;
//--- create an object
if(!FiboLevelsCreate(0,InpName,0,TimeCurrent(),min_price,max_date,max_price,InpColor,
InpStyle,InpWidth,InpBack,InpSelection,InpRayRight,InpHidden,InpZOrder))
{
return;
}
//--- redraw the chart and wait for 1 second
ChartRedraw();
//Sleep(10000);
//FiboLevelsDelete(0,InpName);
//ChartRedraw();
Sleep(1000);
//--- now, move the anchor points
//--- loop counter
//int v_steps=accuracy*2/5;
//--- move the first anchor point
int v_steps = accuracy;
for(int i=0;i<v_steps;i++)
{
//--- use the following value
if(p1>1)
p1-=1;
//--- move the point
if(!FiboLevelsPointChange(0,InpName,0,TimeCurrent(),Bid)) {
Print("x");
return;
}
//--- check if the script's operation has been forcefully disabled
if(IsStopped())
return;
//--- redraw the chart
ChartRedraw();
}
// Sleep(3000);
// FiboLevelsDelete(0,InpName);
ChartRedraw();
/*
//--- 1 second of delay
Sleep(1000);
//--- loop counter
v_steps=accuracy*4/5;
//--- move the second anchor point
for(int i=0;i<v_steps;i++)
{
//--- use the following value
if(p2>1)
p2-=1;
//--- move the point
if(!FiboLevelsPointChange(0,InpName,1,date[d2],price[p2]))
return;
//--- check if the script's operation has been forcefully disabled
if(IsStopped())
return;
//--- redraw the chart
ChartRedraw();
}
//--- 1 second of delay
Sleep(1000);
//--- delete the object from the chart
FiboLevelsDelete(0,InpName);
ChartRedraw();
//--- 1 second of delay
Sleep(1000);
*/
//---
}
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[])
{
int max_shift = 0;
int min_shift = 0;
double max_price = 0;
double min_price = 0;
datetime max_date = 0;
datetime min_date = 0;
int range = 400;
for (int i = Bars; i > 0; i--) {
if (i > range) continue;
max_shift = iHighest(ChartSymbol(), ChartPeriod(), MODE_HIGH, range, i);
min_shift = iLowest(ChartSymbol(), ChartPeriod(), MODE_LOW, range, i);
}
max_price = iHigh(ChartSymbol(), ChartPeriod(), max_shift);
min_price = iLow(ChartSymbol(), ChartPeriod(), min_shift);
max_date = iTime(ChartSymbol(), ChartPeriod(), max_shift);
min_date = iTime(ChartSymbol(), ChartPeriod(), min_shift);
int v_steps = 1000;
for(int i=0;i<v_steps;i++)
{
//--- use the following value
// if(p1>1)
// p1-=1;
//--- move the point
if(!FiboLevelsPointChange(0,InpName,0,min_date,min_price)) {
Print("x");
// return;
}
//--- check if the script's operation has been forcefully disabled
// i//f(IsStopped())
// return;
//--- redraw the chart
// ChartRedraw();
}
// Sleep(3000);
// FiboLevelsDelete(0,InpName);
ChartRedraw();
static long a =0;
// for (int x =0; x< 10; x++) {
if (ObjectGetInteger(0, InpName, OBJPROP_LEVELS, OBJ_FIBO, a)) {
Print( "llllllllllllllll " + a);
}
// }
static double sstr[9];
//ArrayResize(sstr, 7,7);
for (int i = 0; i < a; i++) {
if (ObjectGetDouble(0,InpName,OBJPROP_LEVELVALUE, i, sstr[i])) {
Print( " == > " + i + " --- " + sstr[i]);
} else{
Print(GetLastError());
}
}
static double ss[9];
//ArrayResize(sstr, 7,7);
for (int i = 0; i < a; i++) {
if (ObjectGetDouble(0,InpName,OBJPROP_PRICE, i, ss[i])) {
Print( " == > " + i + " --- " + ss[i]);
double res = (ss[1] - ss[0]);// * SymbolInfoDouble(Symbol(),SYMBOL_POINT);
Print(min_price + (res * sstr[i]));
} else{
Print(GetLastError());
}
}
return 0;
}
https://www.myfxbook.com/members/rookie_t/pycha-kroczy-przed-upadkiem/7931743
- ninjaproject
- Maniak
- Posty: 4944
- Rejestracja: 30 lip 2019, 13:15
Re: Wszystkie pytania dozwolone początkujących programistów
Po kolei:
https://fx1.net/mt4ticker.php
Ktoś przerobił skrypt na wskaźnik.
To tak na szybko.
Co do reszty, to popatrzę jak będę miał więcej czasu.
Pobierz sobie tickera:rookie2 pisze: ↑30 sty 2021, 11:23Na testerze puść jak coś bo OnCalculate teraz nie działa, bo rynek nie chodzi. Albo ustaw w onInit() timer co sekunde czyli EventSetTimer(1); i wstaw kod z onCalculate to void onTimer(). Ogarniesz. U mnie wywala błąd 4051 , Invalid function parameter value https://docs.mql4.com/constants/errorsw ... errorcodes
https://fx1.net/mt4ticker.php
Nie musisz mi mówić co to jest:
Kod: Zaznacz cały
#property strict
//--- description
#property description "Script draws \"Fibonacci Retracement\" graphical object."
#property description "Anchor point coordinates are set in percentage of"
#property description "the chart window size."
//--- display window of the input parameters during the script's launch
//#property script_show_inputs
#property indicator_chart_window
//--- input parameters of the script
To tak na szybko.
Co do reszty, to popatrzę jak będę miał więcej czasu.
Trejder, Mentor/trener, aka. Dadas, fx-technik, obecnie ninjaproject.
Programuję wskaźniki i EA do MetaTrader 4/5.
Programuję wskaźniki i EA do MetaTrader 4/5.
Re: Wszystkie pytania dozwolone początkujących programistów
Ja przerobiłem. To znaczy zmieniłem tylko property na indyka i dodałem funkcje onCalculate i tyle. I jest wskaźnik. Tylko interesuje mnie czemu nie pobiera wszystkich 9 leveli fibo, tylko max i low, 100 i 0 poziom. A jak mnoże przez procenty, w tej pętli, to wychodzą mi jakieś dziwne ceny, może jakby jakoś znormalizować tą wartość, ale nie wiem która to jest funkcja, jak to przeskalować żeby było ok, bo błędnie liczy jak idę tą drogą, a jak widzisz pobrać, pobiera tylko 2 poziomy ;/ninjaproject pisze: ↑30 sty 2021, 12:48To tak na szybko.
Co do reszty, to popatrzę jak będę miał więcej czasu.
https://www.myfxbook.com/members/rookie_t/pycha-kroczy-przed-upadkiem/7931743
- ninjaproject
- Maniak
- Posty: 4944
- Rejestracja: 30 lip 2019, 13:15
Re: Wszystkie pytania dozwolone początkujących programistów
Już wiem:
Nie ma w MT4 bezpośredniej metody odczytania poziomów z OBJ_FIBO.
Czyli, ta pętla zwraca tylko ceny kotwic (ANCHOR).
Resztę trzeba z tego wyliczyć:
Nie ma w MT4 bezpośredniej metody odczytania poziomów z OBJ_FIBO.
Czyli, ta pętla zwraca tylko ceny kotwic (ANCHOR).
Resztę trzeba z tego wyliczyć:
Kod: Zaznacz cały
double getFiboLevel( double up, double dw, double lev, int direction ){
double ling = up - dw;
double pLev = ( ling / 100 ) * lev;
return ( direction < 0 ) ? NormalizeDouble( up - pLev, Digits ) : NormalizeDouble( dw + pLev, Digits ) ;
}
Print( DoubleToString( getFiboLevel( LastZZhigh, LastZZlow, 23.6, 1 ) ) );
Trejder, Mentor/trener, aka. Dadas, fx-technik, obecnie ninjaproject.
Programuję wskaźniki i EA do MetaTrader 4/5.
Programuję wskaźniki i EA do MetaTrader 4/5.