Alert in MQL by some conditions - mql

I need a piece of code or an indicator in mql that checks several conditions at any tick and alerts me with a sound if they are met.
The conditions are as follows:
First, if at that moment there are less than 20 seconds left until the end of the current candle (that is, we have between 1 and 20 seconds until the end of the candle),
And secondly, the length of the body of the candle should be longer than the length of the upper shadow and also longer than the length of the lower shadow.
I would be grateful if anyone could help me.

Related

Tibasic check if character is on screen position

I am trying to make a simple arcade shooter like Galaga in TIBasic. I have successfully created some code that lets you move your character (an "X") horizontally across the screen while shooting a bullet that clears everything along the vertical path it takes. However, I'm having a problem with the "rocks" that are supposed to fall from the screen and disappear when hit. When I shoot the rock, it is cleared by the bullet, but then continues going down the screen until it hits the bottom of the screen. Here's the code for the rocks:
//outside the game loop:
1->R
//inside game loop:
If not(R=8)
Then
R+1->R
If R>1
Then
Output(E-1, 1, " " //removes last rock
End
Output(R, 1, "R" //replaces last rock with one below it (traveling towards the ground)
End
This code obviously doesn't stop the "R" from continuing to go down the screen when it is cleared (by the way, I just use Output(...," ") on wherever the bullet was to clear away anything the bullet hits). So, how would I check if the rock was cleared away on the last iteration of the game loop? Is there a way to check if something (the "R") is at a certain place on the screen in order to check if it was cleared away by a bullet on the last iteration? Or is there a better way? Thanks for the help!
It appears that the code you have doesn't test if the bullet is in the same place as the rock. To have this collision, you'd need to compare the "R" y-value of the rock with the y-value of your bullet you displayed, and compare the x-value of the rock (however you store that) with the x-value of the bullet. If both are equal to each other, then they have collided, and you can "delete" the rock by setting it to whatever value signifies it doesn't exist anymore. Assuming R is the y-value of the rock, S is the x-value of the rock, Y is the y-value of the bullet, and X is the x-value of the bullet, In the code to move the rock, I'd put this somewhere:
:If R=Y and S=X
:DelVar R
//You could also delete the bullet here because it's "stopped" by the rock
This code will test if the two are collided and set R to 0 (meaning it doesn't exist). If you wanted, you could also add a text-version of an explosion to give it some more flair. Good luck with your project, and I hoped this helped!
When making a game in Ti-Basic, there are 2 options for which "screen" to put it on: The text screen of the calculator, using functions like Disp and Output, and the graph screen, using Text, as well as the drawing functions, stored pictures, and pxl and pt functions. I'm not sure about how to check the text out put screen for the presence of an object on the screen, but the graph function has the Pxl-Test function:
:Pxl-Test(y,x)
Someone else may have know how to check for something on the text screen, but I suggest switching to the graph screen to make use of this function.
If you are going to switch to using the graph output here are some things to note:
The text function is
:Text(row,col,output)
Row and col are switched from the Output function
Rows and cols are measured in pixels on the screen, as opposed to the space it takes to type a letter
Most letters are 3 pixels wide, spaces are 1 pixel wide, so it will take multiple spaces to clear out an unwanted character
You may need to disable the graph axis (FORMAT menu), the y-functions (VARS menu, then right to Y-VARS), and the stat-plots (STAT PLOT menu) in the begging of the program then restore them at the end.
One last not on using the Pxl-Test function is that it tests a group of pixels, while a letter. For now let's pretend you only use Rs and an X in your program (I don't know if you do or don't), so you should test a spot on that character that is relatively unique to that character.
Good luck!

How to make randomized numbers but if they are too close, change it

I want to make randomized numbers but if they are too close, I want to make it a reroll or make it a number further away from the the other number or try to make it a little more spread out.
I guess I am not sure what exactly I want :/
Thanks in advance
EDIT: So the reason i am making randomized numbers is for spawning positions for units on sides of the screen so i want units to not be too close to each other essentially to make it look better.
I want to make randomized numbers but if they are too close, I want to
make it a reroll or make it a number further away from the the other
number or try to make it a little more spread out.
A random number generator sometimes produces numbers that are near each other.
If you don't want them so close together, maybe what you need is fixed numbers each with a small random perturbation.
Let's say you choose numbers 10, 20, 30, 40, and 50. Then, you run a random number generator that gives you a number between -3 and +3. You add this random number to each one in turn. This produces numbers that aren't uniform, but they're not too close to one another.
If a re-roll would be sufficient, you could just save the previous value, and then on the next iteration, if the difference between the two numbers is too small, call Math.rand() again. Maybe your sample space is too small?
Get random position
If it's not good (too close to some other or what ever) go to step 1.
There you go! You got valid position. :)
...
Or...pre-calculate all valid positions, place them in some array and use rnd function to get array indexes - what array elements will use. That should be the faster solution (if you have huge number of units)...

Remove child from Batch node one after another with a pause

I am trying to remove a set of children from the batch node one by one after some pause . So if three children are there, then firstly parent will disappear immidiatley , then after 1 second first child will disappear, then after another 1 second(total 2 seconds) 2nd child will disappear and after another 1 second(total 3 seconds) third child will disappear.
Right now I am removing them from the batchnode like :-
batchNode->removeChild(child1,true);
sleep(1);
batchNode->removeChild(child2,true);
sleep(2)
batchNode->removeChild(child3,true);
But they all disappear from screen at same time ! although pause is there. Is it because they all are part of same batchNode so any action taken on children will be applied at one go. ?
Please share your thoughts
ie, they all disappear together after 3 seconds ? Basically, i think that the sleep is actually blocking the main thread, so the update & draw cycle will only resume after the last one of your statements.
I would do something like that by running some kind of CCSequence , with delay actions and callBlock actions to cascade properly. This is all executed within the main thread, so the display will be refreshed during the cascade.
Sleep() argument is typically measured in milliseconds, so try sleep(1000); in second and fourth lines.
Also, maybe, you'd better to use Actions (CCSequence stuffed with CCDelay and CCCallFunc) instead of sleep() which blocks all your game.
I am able to do it , I used two different ways as described:-
1> By postponing the removal of subsequent children in further frames.
2> or instead of depending on the frames, I used delta time (time since the last frame was drawn).So remove a child only after say 0.5 secs.
Using either of the above way , I can omit the use of sleep which can hog my main thread.
Here are the details, considering I have in total three children to remove:-
1> By postponing the removal of subsequent children in further frames.
In the current frame I will remove first child then will set a flag to notify in the Update not to do anything but wait for say 15 frames, while waiting 15 frames I can do other tasks also which doesnot have impact on gameplay
Although with this I have flexibility to wait for any number of frames, but I will have to regulate the frame rate for different devices, as in slow devices, waiting 15 frames can take more time than fast device, and I am not able to know if cocos2dx does regulate the frame rate itself, so I quickly jumped to next solution.
2> or instead of depending on the frames, I used delta time (time since the last frame was drawn).So remove a child only after say 0.5 secs.
Here instead of waiting 15 frames I used following condition inside Update(float dt):-
if(gameState==WaitForNextChildRemoval)
{
deltaTime=deltaTime+dt;
if(deltaTime>=0.5)
{
releaseNextChild();
deltaTime=0;
}
}
here irrespective of the device(slow or fast), next child will be removed after 0.5 secs.
One improvement I think should be made is when deltaTime becomes more than say 1 sec , and then instead of removing only next one child, it should remove two children (0.5 secs for each) at one go , as player is expecting to remove one child after 0.5 secs so deltaTime being 1 sec(approx), I should balance this expectation.
Please share your thoughts.

Gradually rotate towards a direction

I have a car object, and I want it to gradually rotate to the direction where the user clicked.
Every frame I did math to calculate the new direction it needs, and it's stored at car.direction. The actual direction is of course in car.rotation.
Now I want to update the rotation every frame until it's equal to the direction. However I tried everything and can't figure out how to do that.
By the way, I'm using FireFly, that is a gameengine built on top of Starling Framework, But I don't think it's relevant.
I would go with Marty's suggestion, use the smallestAngle function to determine which direction you should be rotating. Basically you can move some percentage of the smallestAngle during every frame update until the percentage of that smallestAngle is below some threshold (and have it "snap" the rest of the way).
Something like
//each time this is called it will get 1/4 closer, but never get to 0, hence the need for a threshold avoid paradoxes
//http://en.wikipedia.org/wiki/Zeno's_paradoxes#Dichotomy_paradox
var angleToMove:Number = smallestAngle()/4; //the divide by 4 here means get 1/4 of the angle gap closer each time this function is called, I assume this is on a timer or frame handler, making the 4 greater will make it follow more slowly, making it lower will make it follow more quickly, never reduce to or below 0 unless you want wonkiness
if(angleToMove<someRadianThreshold)
angleToMove = smallestAngle();
//use angleToMove to adjust the current heading/rotation

Need help understanding Conway's Game of Life

I'm trying to write code for Conway's Game of Life to determine the immediate next pattern for a given pattern of cells, but I'm not sure whether I really understand the steps. So for example consider the below toad pattern. The cells marked x are alive and those marked - are dead.
-XXX
XXX-
The above should transpose into the following
--x-
x--x
x--x
-x--
The rules as we know are:
A live cell with less than 2 or more than 3 neighbours dies
A live cell with exactly 2 or 3 neighbours survives
A dead cell with exactly 3 neighbours comes to life.
So, the first cell in the input c[0,0] is - and it has 3 live neigbours (one horizontally,vertically and diagonally each), so it should be alive in the output, but it's not. Can someone please explain?
The middle two rows in your output are the ones that correspond to the two rows in your input. The upper left cell in the input corresponds to the second row extreme left in the output, and as you can see, it's alive.
It is alive in the output. It's right here:
--x-
x--x
x--x
-x--
The x in the first row is above the first row in the first output. The rules of Life assume an unbounded plane. If you want to call the top row of the first output 0, you can, but then the top row of the second output is -1.
Well it is. Your 2-line long input is the middle part of your 4-line output. I think when you look at it now you'll understand everything.
Have you looked at least at wikipedia?