本文介绍了如何获取图表HLine对象的价格并计算斐波那契水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
三部分问题:
- 如何在图表上按名称查找用户创建的2条水平线并返回其价格.
- 然后确定最近的价格与哪个HLine交叉以确定趋势方向.
- 根据价格和方向计算斐波那契水平
- How to find 2 user created horizontal lines on a chart by name and return the price of each.
- Then determine which HLine was crossed by the price most recently to determine trend direction.
- Calculate Fibonacci levels based on prices and direction
推荐答案
斐波那契对象的工作示例,该对象可以由用户编辑并打印斐波那契水平.
Working example of Fibonacci object that can be edited by the user and printing of fibonacci levels.
#include <ChartObjects/ChartObjectsFibo.mqh>
CChartObjectFibo *Fibo;
int OnInit()
{
Fibo = new CChartObjectFibo();
#Create object and set some defaults
if(!Fibo.Create(0,"Fibonacci",0,Time[5],Open[5],Time[0],Open[0]))
{
return(INIT_FAILED);
}
# Allow user to drag object
Fibo.Selectable(true);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
delete Fibo;
}
void OnTick()
{
string level_description;
double level_value;
string printString="Fibonacci Levels - ";
# Get the two anchor prices
double p1 = Fibo.GetDouble(OBJPROP_PRICE,0);
double p2 = Fibo.GetDouble(OBJPROP_PRICE,1);
# Calculate range
double range=MathAbs(p1-p2);
for(int i=0;i<Fibo.LevelsCount();i++)
{
level_description=Fibo.LevelDescription(i);
# Calculate price of level
level_value=(p2>p1)?p2-range*Fibo.LevelValue(i):p2+range*Fibo.LevelValue(i);
printString=StringFormat("%s %s:%.5f",printString,level_description,level_value);
}
Print(printString);
}
这篇关于如何获取图表HLine对象的价格并计算斐波那契水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!